From 957f27663ac22579762a7df7453da52aaf69bfdc Mon Sep 17 00:00:00 2001 From: Owl Bot Date: Mon, 14 Apr 2025 15:09:39 +0000 Subject: [PATCH] chore(python): remove testing dir from templates Source-Link: https://github.com/googleapis/synthtool/commit/9b7ef37660481408a2e4685fc1f59e1b60bd149f Post-Processor: gcr.io/cloud-devrel-public-resources/owlbot-python:latest@sha256:21c50ac6b72047705ceac7b3c84dca11f771f40b5cdfd8931bf1f446a89274e5 --- .github/.OwlBot.lock.yaml | 4 +-- noxfile.py | 70 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/.github/.OwlBot.lock.yaml b/.github/.OwlBot.lock.yaml index c631e1f7d7..efe09f2a34 100644 --- a/.github/.OwlBot.lock.yaml +++ b/.github/.OwlBot.lock.yaml @@ -13,5 +13,5 @@ # limitations under the License. docker: image: gcr.io/cloud-devrel-public-resources/owlbot-python:latest - digest: sha256:5581906b957284864632cde4e9c51d1cc66b0094990b27e689132fe5cd036046 -# created: 2025-03-05 + digest: sha256:21c50ac6b72047705ceac7b3c84dca11f771f40b5cdfd8931bf1f446a89274e5 +# created: 2025-04-14T15:05:23.836138399Z diff --git a/noxfile.py b/noxfile.py index cb683afd7e..4bc9bfc44a 100644 --- a/noxfile.py +++ b/noxfile.py @@ -34,6 +34,7 @@ DEFAULT_PYTHON_VERSION = "3.8" +DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12" DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12" UNIT_TEST_PYTHON_VERSIONS: List[str] = [ "3.7", @@ -193,6 +194,30 @@ def install_unittest_dependencies(session, *constraints): *session.posargs, ) + # XXX Work around Kokoro image's older pip, which borks the OT install. + session.run("pip", "install", "--upgrade", "pip") + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + session.install("-e", ".[tracing]", "-c", constraints_path) + # XXX: Dump installed versions to debug OT issue + session.run("pip", "list") + + # Run py.test against the unit tests with OpenTelemetry. + session.run( + "py.test", + "--quiet", + "--cov=google.cloud.spanner", + "--cov=google.cloud", + "--cov=tests.unit", + "--cov-append", + "--cov-config=.coveragerc", + "--cov-report=", + "--cov-fail-under=0", + os.path.join("tests", "unit"), + *session.posargs, + ) + @nox.session(python=UNIT_TEST_PYTHON_VERSIONS) @nox.parametrize( @@ -263,6 +288,34 @@ def mockserver(session): ) +@nox.session(python=DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION) +def mockserver(session): + # Install all test dependencies, then install this package in-place. + + constraints_path = str( + CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt" + ) + # install_unittest_dependencies(session, "-c", constraints_path) + standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES + session.install(*standard_deps, "-c", constraints_path) + session.install("-e", ".", "-c", constraints_path) + + # Run py.test against the mockserver tests. + session.run( + "py.test", + "--quiet", + f"--junitxml=unit_{session.python}_sponge_log.xml", + "--cov=google", + "--cov=tests/unit", + "--cov-append", + "--cov-config=.coveragerc", + "--cov-report=", + "--cov-fail-under=0", + os.path.join("tests", "mockserver_tests"), + *session.posargs, + ) + + def install_systemtest_dependencies(session, *constraints): # Use pre-release gRPC for system tests. # Exclude version 1.52.0rc1 which has a known issue. @@ -327,6 +380,17 @@ def system(session, protobuf_implementation, database_dialect): if os.environ.get("SPANNER_EMULATOR_HOST") and database_dialect == "POSTGRESQL": session.skip("Postgresql is not supported by Emulator yet.") + # Sanity check: Only run tests if the environment variable is set. + if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") and not os.environ.get( + "SPANNER_EMULATOR_HOST", "" + ): + session.skip( + "Credentials or emulator host must be set via environment variable" + ) + # If POSTGRESQL tests and Emulator, skip the tests + if os.environ.get("SPANNER_EMULATOR_HOST") and database_dialect == "POSTGRESQL": + session.skip("Postgresql is not supported by Emulator yet.") + # Install pyopenssl for mTLS testing. if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true": session.install("pyopenssl") @@ -339,6 +403,12 @@ def system(session, protobuf_implementation, database_dialect): install_systemtest_dependencies(session, "-c", constraints_path) + # TODO(https://github.com/googleapis/synthtool/issues/1976): + # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. + # The 'cpp' implementation requires Protobuf<4. + if protobuf_implementation == "cpp": + session.install("protobuf<4") + # TODO(https://github.com/googleapis/synthtool/issues/1976): # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped. # The 'cpp' implementation requires Protobuf<4.