From 89ba292281970cbdee5bb43b45a9dac69e29ff0a Mon Sep 17 00:00:00 2001 From: arithmetic1728 <58957152+arithmetic1728@users.noreply.github.com> Date: Tue, 5 Jan 2021 12:50:33 -0800 Subject: [PATCH] fix: skip some system tests for mtls testing (#106) --- tests/system/v1/conftest.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tests/system/v1/conftest.py b/tests/system/v1/conftest.py index cb8c5c19..f8ac01f5 100644 --- a/tests/system/v1/conftest.py +++ b/tests/system/v1/conftest.py @@ -33,9 +33,20 @@ def project_id(): @pytest.fixture(scope="session") -def credentials(): +def use_mtls(): + return "always" == os.environ.get("GOOGLE_API_USE_MTLS_ENDPOINT", "never") + + +@pytest.fixture(scope="session") +def credentials(use_mtls): + import google.auth from google.oauth2 import service_account + if use_mtls: + # mTLS test uses user credentials instead of service account credentials + creds, _ = google.auth.default() + return creds + # NOTE: the test config in noxfile checks that the env variable is indeed set filename = os.environ["GOOGLE_APPLICATION_CREDENTIALS"] return service_account.Credentials.from_service_account_file(filename) @@ -59,7 +70,11 @@ def small_table_reference(): @pytest.fixture(scope="session") -def local_shakespeare_table_reference(project_id): +def local_shakespeare_table_reference(project_id, use_mtls): + if use_mtls: + pytest.skip( + "Skip it for mTLS testing since the table does not exist for mTLS project" + ) return _TABLE_FORMAT.format(project_id, "public_samples_copy", "shakespeare") @@ -100,7 +115,9 @@ def table(project_id, dataset, bq_client): @pytest.fixture(scope="session") -def bq_client(credentials): +def bq_client(credentials, use_mtls): + if use_mtls: + pytest.skip("Skip it for mTLS testing since bigquery does not support mTLS") from google.cloud import bigquery return bigquery.Client(credentials=credentials)