Skip to content
This repository was archived by the owner on Mar 31, 2026. It is now read-only.

Commit 90d8192

Browse files
1 parent 81bab46 commit 90d8192

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

noxfile.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434

3535
DEFAULT_PYTHON_VERSION = "3.8"
3636

37+
DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12"
3738
DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12"
3839
DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12"
3940
UNIT_TEST_PYTHON_VERSIONS: List[str] = [
@@ -218,6 +219,30 @@ def install_unittest_dependencies(session, *constraints):
218219
*session.posargs,
219220
)
220221

222+
# XXX Work around Kokoro image's older pip, which borks the OT install.
223+
session.run("pip", "install", "--upgrade", "pip")
224+
constraints_path = str(
225+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
226+
)
227+
session.install("-e", ".[tracing]", "-c", constraints_path)
228+
# XXX: Dump installed versions to debug OT issue
229+
session.run("pip", "list")
230+
231+
# Run py.test against the unit tests with OpenTelemetry.
232+
session.run(
233+
"py.test",
234+
"--quiet",
235+
"--cov=google.cloud.spanner",
236+
"--cov=google.cloud",
237+
"--cov=tests.unit",
238+
"--cov-append",
239+
"--cov-config=.coveragerc",
240+
"--cov-report=",
241+
"--cov-fail-under=0",
242+
os.path.join("tests", "unit"),
243+
*session.posargs,
244+
)
245+
221246

222247
@nox.session(python=UNIT_TEST_PYTHON_VERSIONS)
223248
@nox.parametrize(
@@ -316,6 +341,34 @@ def mockserver(session):
316341
)
317342

318343

344+
@nox.session(python=DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION)
345+
def mockserver(session):
346+
# Install all test dependencies, then install this package in-place.
347+
348+
constraints_path = str(
349+
CURRENT_DIRECTORY / "testing" / f"constraints-{session.python}.txt"
350+
)
351+
# install_unittest_dependencies(session, "-c", constraints_path)
352+
standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
353+
session.install(*standard_deps, "-c", constraints_path)
354+
session.install("-e", ".", "-c", constraints_path)
355+
356+
# Run py.test against the mockserver tests.
357+
session.run(
358+
"py.test",
359+
"--quiet",
360+
f"--junitxml=unit_{session.python}_sponge_log.xml",
361+
"--cov=google",
362+
"--cov=tests/unit",
363+
"--cov-append",
364+
"--cov-config=.coveragerc",
365+
"--cov-report=",
366+
"--cov-fail-under=0",
367+
os.path.join("tests", "mockserver_tests"),
368+
*session.posargs,
369+
)
370+
371+
319372
def install_systemtest_dependencies(session, *constraints):
320373
# Use pre-release gRPC for system tests.
321374
# Exclude version 1.52.0rc1 which has a known issue.
@@ -391,6 +444,17 @@ def system(session, protobuf_implementation, database_dialect):
391444
if os.environ.get("SPANNER_EMULATOR_HOST") and database_dialect == "POSTGRESQL":
392445
session.skip("Postgresql is not supported by Emulator yet.")
393446

447+
# Sanity check: Only run tests if the environment variable is set.
448+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") and not os.environ.get(
449+
"SPANNER_EMULATOR_HOST", ""
450+
):
451+
session.skip(
452+
"Credentials or emulator host must be set via environment variable"
453+
)
454+
# If POSTGRESQL tests and Emulator, skip the tests
455+
if os.environ.get("SPANNER_EMULATOR_HOST") and database_dialect == "POSTGRESQL":
456+
session.skip("Postgresql is not supported by Emulator yet.")
457+
394458
# Install pyopenssl for mTLS testing.
395459
if os.environ.get("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false") == "true":
396460
session.install("pyopenssl")
@@ -415,6 +479,12 @@ def system(session, protobuf_implementation, database_dialect):
415479
if protobuf_implementation == "cpp":
416480
session.install("protobuf<4")
417481

482+
# TODO(https://github.com/googleapis/synthtool/issues/1976):
483+
# Remove the 'cpp' implementation once support for Protobuf 3.x is dropped.
484+
# The 'cpp' implementation requires Protobuf<4.
485+
if protobuf_implementation == "cpp":
486+
session.install("protobuf<4")
487+
418488
# Run py.test against the system tests.
419489
if system_test_exists:
420490
session.run(

0 commit comments

Comments
 (0)