From aed9b1d25bf0e4b3a0d745b35183f4c4bd1c7f15 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 13:36:04 +0000 Subject: [PATCH 1/9] for testing purposes --- noxfile.py | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/noxfile.py b/noxfile.py index fb2c1ee..b5187b7 100644 --- a/noxfile.py +++ b/noxfile.py @@ -333,7 +333,8 @@ def prerelease_deps(session): # Install all dependencies session.install("-e", ".[all, tests, tracing]") - session.install(*UNIT_TEST_STANDARD_DEPENDENCIES) + unit_deps_all2 = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*unit_deps_all2) system_deps_all = ( SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES @@ -404,11 +405,31 @@ def prerelease_deps(session): system_test_folder_path = os.path.join("tests", "system") # Only run system tests if found. - if os.path.exists(system_test_path) or os.path.exists(system_test_folder_path): - session.run("py.test", "tests/system") + if os.path.exists(system_test_path): + session.run( + "py.test", + "--verbose", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_path, + *session.posargs, + ) + if os.path.exists(system_test_folder_path): + session.run( + "py.test", + "--verbose", + f"--junitxml=system_{session.python}_sponge_log.xml", + system_test_folder_path, + *session.posargs, + ) snippets_test_path = os.path.join("samples", "snippets") # Only run samples tests if found. if os.path.exists(snippets_test_path): - session.run("py.test", "samples/snippets") + session.run( + "py.test", + "--verbose", + f"--junitxml=system_{session.python}_sponge_log.xml", + snippets_test_path, + *session.posargs, + ) From b7a3a92842c693026c16ba7c75a607fa98ac2d0a Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 13:53:10 +0000 Subject: [PATCH 2/9] test --- noxfile.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/noxfile.py b/noxfile.py index b5187b7..153afd1 100644 --- a/noxfile.py +++ b/noxfile.py @@ -21,6 +21,7 @@ import pathlib import re import shutil +import sys import warnings import nox @@ -330,6 +331,43 @@ def docfx(session): @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def prerelease_deps(session): """Run all tests with prerelease versions of dependencies installed.""" + # `TEST_CONFIG` dict is a configuration hook that allows users to + # modify the test configurations. The values here should be in sync + # with `noxfile_config.py`. Users will copy `noxfile_config.py` into + # their directory and modify it. + + TEST_CONFIG = { + # You can opt out from the test for specific Python versions. + "ignored_versions": [], + # Old samples are opted out of enforcing Python type hints + # All new samples should feature them + "enforce_type_hints": False, + # An envvar key for determining the project id to use. Change it + # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a + # build specific Cloud project. You can also use your own string + # to use your own Cloud project. + "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", + # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', + # If you need to use a specific version of pip, + # change pip_version_override to the string representation + # of the version number, for example, "20.2.4" + "pip_version_override": None, + # A dictionary you want to inject into your test. Don't put any + # secrets here. These values will override predefined values. + "envs": {}, + } + + + try: + # Ensure we can import noxfile_config in the project's directory. + sys.path.append("samples/snippets") + from samples.snippets.noxfile_config import TEST_CONFIG_OVERRIDE + except ImportError as e: + print("No user noxfile_config found: detail: {}".format(e)) + TEST_CONFIG_OVERRIDE = {} + + # Update the TEST_CONFIG with the user supplied values. + TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) # Install all dependencies session.install("-e", ".[all, tests, tracing]") @@ -433,3 +471,4 @@ def prerelease_deps(session): snippets_test_path, *session.posargs, ) + From 7e41bc284ed372df29a046fe5275fb17dbd67ab1 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 13:55:50 +0000 Subject: [PATCH 3/9] test --- noxfile.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/noxfile.py b/noxfile.py index 153afd1..44b18cc 100644 --- a/noxfile.py +++ b/noxfile.py @@ -25,6 +25,7 @@ import warnings import nox +from typing import Dict BLACK_VERSION = "black==22.3.0" ISORT_VERSION = "isort==5.10.1" @@ -337,27 +338,13 @@ def prerelease_deps(session): # their directory and modify it. TEST_CONFIG = { - # You can opt out from the test for specific Python versions. - "ignored_versions": [], - # Old samples are opted out of enforcing Python type hints - # All new samples should feature them - "enforce_type_hints": False, # An envvar key for determining the project id to use. Change it # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a # build specific Cloud project. You can also use your own string # to use your own Cloud project. "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - # 'gcloud_project_env': 'BUILD_SPECIFIC_GCLOUD_PROJECT', - # If you need to use a specific version of pip, - # change pip_version_override to the string representation - # of the version number, for example, "20.2.4" - "pip_version_override": None, - # A dictionary you want to inject into your test. Don't put any - # secrets here. These values will override predefined values. - "envs": {}, } - try: # Ensure we can import noxfile_config in the project's directory. sys.path.append("samples/snippets") @@ -369,6 +356,19 @@ def prerelease_deps(session): # Update the TEST_CONFIG with the user supplied values. TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + def get_pytest_env_vars() -> Dict[str, str]: + """Returns a dict for pytest invocation.""" + ret = {} + + # Override the GCLOUD_PROJECT and the alias. + env_key = TEST_CONFIG["gcloud_project_env"] + # This should error out if not set. + ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] + + # Apply user supplied envs. + ret.update(TEST_CONFIG["envs"]) + return ret + # Install all dependencies session.install("-e", ".[all, tests, tracing]") unit_deps_all2 = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES @@ -470,5 +470,6 @@ def prerelease_deps(session): f"--junitxml=system_{session.python}_sponge_log.xml", snippets_test_path, *session.posargs, + env=get_pytest_env_vars(), ) From e2068a67179cb92a25a7b51ce71d813ab2dc7313 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 13:58:06 +0000 Subject: [PATCH 4/9] lint --- noxfile.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/noxfile.py b/noxfile.py index 44b18cc..8663197 100644 --- a/noxfile.py +++ b/noxfile.py @@ -354,7 +354,7 @@ def prerelease_deps(session): TEST_CONFIG_OVERRIDE = {} # Update the TEST_CONFIG with the user supplied values. - TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) + TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) def get_pytest_env_vars() -> Dict[str, str]: """Returns a dict for pytest invocation.""" @@ -368,7 +368,7 @@ def get_pytest_env_vars() -> Dict[str, str]: # Apply user supplied envs. ret.update(TEST_CONFIG["envs"]) return ret - + # Install all dependencies session.install("-e", ".[all, tests, tracing]") unit_deps_all2 = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES @@ -472,4 +472,3 @@ def get_pytest_env_vars() -> Dict[str, str]: *session.posargs, env=get_pytest_env_vars(), ) - From d981dff3fcc92eb22ddb1f0018a2eb7c3d3d985c Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 14:07:42 +0000 Subject: [PATCH 5/9] test --- .kokoro/presubmit/prerelease-deps.cfg | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.kokoro/presubmit/prerelease-deps.cfg b/.kokoro/presubmit/prerelease-deps.cfg index 3595fb4..26552e4 100644 --- a/.kokoro/presubmit/prerelease-deps.cfg +++ b/.kokoro/presubmit/prerelease-deps.cfg @@ -5,3 +5,8 @@ env_vars: { key: "NOX_SESSION" value: "prerelease_deps" } + +env_vars: { + key: "TRAMPOLINE_BUILD_FILE" + value: "github/python-analytics-data/.kokoro/test-samples.sh" +} From 0b9ee8cef63886b6ae8c96b7c2d693c14639e038 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 14:12:03 +0000 Subject: [PATCH 6/9] test --- .kokoro/presubmit/prerelease-deps.cfg | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.kokoro/presubmit/prerelease-deps.cfg b/.kokoro/presubmit/prerelease-deps.cfg index 26552e4..c4d8196 100644 --- a/.kokoro/presubmit/prerelease-deps.cfg +++ b/.kokoro/presubmit/prerelease-deps.cfg @@ -10,3 +10,18 @@ env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-analytics-data/.kokoro/test-samples.sh" } + +# Configure the docker image for kokoro-trampoline. +env_vars: { + key: "TRAMPOLINE_IMAGE" + value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker" +} + +# Download secrets for samples +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" + +# Download trampoline resources. +gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" + +# Use the trampoline script to run in docker. +build_file: "python-analytics-data/.kokoro/trampoline_v2.sh" \ No newline at end of file From 9c9212a07d25b1da376f046d1da7963c0090e324 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 14:20:43 +0000 Subject: [PATCH 7/9] test --- .kokoro/presubmit/prerelease-deps.cfg | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.kokoro/presubmit/prerelease-deps.cfg b/.kokoro/presubmit/prerelease-deps.cfg index c4d8196..a91456a 100644 --- a/.kokoro/presubmit/prerelease-deps.cfg +++ b/.kokoro/presubmit/prerelease-deps.cfg @@ -1,11 +1,12 @@ # Format: //devtools/kokoro/config/proto/build.proto -# Only run this nox session. +# Specify which tests to run env_vars: { - key: "NOX_SESSION" + key: "RUN_TESTS_SESSION" value: "prerelease_deps" } + env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-analytics-data/.kokoro/test-samples.sh" From 90f8f58b527776eefac9d0f100d140c913804260 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 14:26:26 +0000 Subject: [PATCH 8/9] test --- .kokoro/presubmit/prerelease-deps.cfg | 5 ++--- .kokoro/test-samples-impl.sh | 7 ++++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.kokoro/presubmit/prerelease-deps.cfg b/.kokoro/presubmit/prerelease-deps.cfg index a91456a..c4d8196 100644 --- a/.kokoro/presubmit/prerelease-deps.cfg +++ b/.kokoro/presubmit/prerelease-deps.cfg @@ -1,12 +1,11 @@ # Format: //devtools/kokoro/config/proto/build.proto -# Specify which tests to run +# Only run this nox session. env_vars: { - key: "RUN_TESTS_SESSION" + key: "NOX_SESSION" value: "prerelease_deps" } - env_vars: { key: "TRAMPOLINE_BUILD_FILE" value: "github/python-analytics-data/.kokoro/test-samples.sh" diff --git a/.kokoro/test-samples-impl.sh b/.kokoro/test-samples-impl.sh index 2c6500c..1190017 100755 --- a/.kokoro/test-samples-impl.sh +++ b/.kokoro/test-samples-impl.sh @@ -75,8 +75,13 @@ for file in samples/**/requirements.txt; do echo "- testing $file" echo "------------------------------------------------------------" + # Use nox to execute the tests for the project. - python3.9 -m nox -s "$RUN_TESTS_SESSION" + if [[ -z "${RUN_TESTS_SESSION}" ]]; then + python3.9 -m nox -s "$NOX_SESSION" + else + python3.9 -m nox -s "$RUN_TESTS_SESSION" + fi EXIT=$? # If this is a periodic build, send the test log to the FlakyBot. From 0be7e17a0dbdc5a312dcae90ba7c75456e40092e Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sun, 24 Jul 2022 14:36:00 +0000 Subject: [PATCH 9/9] revert --- .kokoro/presubmit/prerelease-deps.cfg | 20 --------- .kokoro/test-samples-impl.sh | 7 +-- noxfile.py | 61 +-------------------------- 3 files changed, 3 insertions(+), 85 deletions(-) diff --git a/.kokoro/presubmit/prerelease-deps.cfg b/.kokoro/presubmit/prerelease-deps.cfg index c4d8196..3595fb4 100644 --- a/.kokoro/presubmit/prerelease-deps.cfg +++ b/.kokoro/presubmit/prerelease-deps.cfg @@ -5,23 +5,3 @@ env_vars: { key: "NOX_SESSION" value: "prerelease_deps" } - -env_vars: { - key: "TRAMPOLINE_BUILD_FILE" - value: "github/python-analytics-data/.kokoro/test-samples.sh" -} - -# Configure the docker image for kokoro-trampoline. -env_vars: { - key: "TRAMPOLINE_IMAGE" - value: "gcr.io/cloud-devrel-kokoro-resources/python-samples-testing-docker" -} - -# Download secrets for samples -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/python-docs-samples" - -# Download trampoline resources. -gfile_resources: "/bigstore/cloud-devrel-kokoro-resources/trampoline" - -# Use the trampoline script to run in docker. -build_file: "python-analytics-data/.kokoro/trampoline_v2.sh" \ No newline at end of file diff --git a/.kokoro/test-samples-impl.sh b/.kokoro/test-samples-impl.sh index 1190017..2c6500c 100755 --- a/.kokoro/test-samples-impl.sh +++ b/.kokoro/test-samples-impl.sh @@ -75,13 +75,8 @@ for file in samples/**/requirements.txt; do echo "- testing $file" echo "------------------------------------------------------------" - # Use nox to execute the tests for the project. - if [[ -z "${RUN_TESTS_SESSION}" ]]; then - python3.9 -m nox -s "$NOX_SESSION" - else - python3.9 -m nox -s "$RUN_TESTS_SESSION" - fi + python3.9 -m nox -s "$RUN_TESTS_SESSION" EXIT=$? # If this is a periodic build, send the test log to the FlakyBot. diff --git a/noxfile.py b/noxfile.py index 8663197..f914194 100644 --- a/noxfile.py +++ b/noxfile.py @@ -21,11 +21,9 @@ import pathlib import re import shutil -import sys import warnings import nox -from typing import Dict BLACK_VERSION = "black==22.3.0" ISORT_VERSION = "isort==5.10.1" @@ -332,47 +330,11 @@ def docfx(session): @nox.session(python=SYSTEM_TEST_PYTHON_VERSIONS) def prerelease_deps(session): """Run all tests with prerelease versions of dependencies installed.""" - # `TEST_CONFIG` dict is a configuration hook that allows users to - # modify the test configurations. The values here should be in sync - # with `noxfile_config.py`. Users will copy `noxfile_config.py` into - # their directory and modify it. - - TEST_CONFIG = { - # An envvar key for determining the project id to use. Change it - # to 'BUILD_SPECIFIC_GCLOUD_PROJECT' if you want to opt in using a - # build specific Cloud project. You can also use your own string - # to use your own Cloud project. - "gcloud_project_env": "GOOGLE_CLOUD_PROJECT", - } - - try: - # Ensure we can import noxfile_config in the project's directory. - sys.path.append("samples/snippets") - from samples.snippets.noxfile_config import TEST_CONFIG_OVERRIDE - except ImportError as e: - print("No user noxfile_config found: detail: {}".format(e)) - TEST_CONFIG_OVERRIDE = {} - - # Update the TEST_CONFIG with the user supplied values. - TEST_CONFIG.update(TEST_CONFIG_OVERRIDE) - - def get_pytest_env_vars() -> Dict[str, str]: - """Returns a dict for pytest invocation.""" - ret = {} - - # Override the GCLOUD_PROJECT and the alias. - env_key = TEST_CONFIG["gcloud_project_env"] - # This should error out if not set. - ret["GOOGLE_CLOUD_PROJECT"] = os.environ[env_key] - - # Apply user supplied envs. - ret.update(TEST_CONFIG["envs"]) - return ret # Install all dependencies session.install("-e", ".[all, tests, tracing]") - unit_deps_all2 = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES - session.install(*unit_deps_all2) + unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*unit_deps_all) system_deps_all = ( SYSTEM_TEST_STANDARD_DEPENDENCIES + SYSTEM_TEST_EXTERNAL_DEPENDENCIES @@ -401,12 +363,6 @@ def get_pytest_env_vars() -> Dict[str, str]: session.install(*constraints_deps) - if os.path.exists("samples/snippets/requirements.txt"): - session.install("-r", "samples/snippets/requirements.txt") - - if os.path.exists("samples/snippets/requirements-test.txt"): - session.install("-r", "samples/snippets/requirements-test.txt") - prerel_deps = [ "protobuf", # dependency of grpc @@ -459,16 +415,3 @@ def get_pytest_env_vars() -> Dict[str, str]: system_test_folder_path, *session.posargs, ) - - snippets_test_path = os.path.join("samples", "snippets") - - # Only run samples tests if found. - if os.path.exists(snippets_test_path): - session.run( - "py.test", - "--verbose", - f"--junitxml=system_{session.python}_sponge_log.xml", - snippets_test_path, - *session.posargs, - env=get_pytest_env_vars(), - )