diff --git a/dev_tools/conftest.py b/dev_tools/conftest.py index 2e7bb5fc556..708c77a3347 100644 --- a/dev_tools/conftest.py +++ b/dev_tools/conftest.py @@ -11,6 +11,7 @@ # 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 @@ -18,6 +19,7 @@ import uuid from pathlib import Path from typing import Tuple +from unittest import mock import pytest from filelock import FileLock @@ -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.