Skip to content

Commit

Permalink
Disable local Google Cloud credentials in tests (#6851)
Browse files Browse the repository at this point in the history
Prevent tested notebooks from connecting to cloud services with
local user credentials.  Tell gcloud to use empty configuration
directory instead of user configuration within pytest session.

This makes the test of docs/tutorials/google/start.ipynb notebook
use virtual hardware engine unconditionally.
  • Loading branch information
pavoljuhas authored Dec 13, 2024
1 parent 4d03aea commit ea605d4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions dev_tools/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import os
import shutil
import sys
import tempfile
import uuid
from pathlib import Path
from typing import Tuple
from unittest import mock

import pytest
from filelock import FileLock
Expand All @@ -26,6 +28,14 @@
from dev_tools.env_tools import create_virtual_env


@pytest.fixture(scope="session", autouse=True)
def disable_local_gcloud_credentials(tmp_path_factory):
# Ensure tests cannot authenticate to production servers with user credentials
empty_dir = tmp_path_factory.mktemp("empty_gcloud_config", numbered=False)
with mock.patch.dict(os.environ, {"CLOUDSDK_CONFIG": str(empty_dir)}):
yield


@pytest.fixture(scope="session")
def cloned_env(testrun_uid, worker_id):
"""Fixture to allow tests to run in a clean virtual env.
Expand Down

0 comments on commit ea605d4

Please sign in to comment.