3434
3535DEFAULT_PYTHON_VERSION = "3.8"
3636
37+ DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12"
3738DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION = "3.12"
3839UNIT_TEST_PYTHON_VERSIONS : List [str ] = [
3940 "3.7" ,
@@ -193,6 +194,30 @@ def install_unittest_dependencies(session, *constraints):
193194 * session .posargs ,
194195 )
195196
197+ # XXX Work around Kokoro image's older pip, which borks the OT install.
198+ session .run ("pip" , "install" , "--upgrade" , "pip" )
199+ constraints_path = str (
200+ CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
201+ )
202+ session .install ("-e" , ".[tracing]" , "-c" , constraints_path )
203+ # XXX: Dump installed versions to debug OT issue
204+ session .run ("pip" , "list" )
205+
206+ # Run py.test against the unit tests with OpenTelemetry.
207+ session .run (
208+ "py.test" ,
209+ "--quiet" ,
210+ "--cov=google.cloud.spanner" ,
211+ "--cov=google.cloud" ,
212+ "--cov=tests.unit" ,
213+ "--cov-append" ,
214+ "--cov-config=.coveragerc" ,
215+ "--cov-report=" ,
216+ "--cov-fail-under=0" ,
217+ os .path .join ("tests" , "unit" ),
218+ * session .posargs ,
219+ )
220+
196221
197222@nox .session (python = UNIT_TEST_PYTHON_VERSIONS )
198223@nox .parametrize (
@@ -263,6 +288,34 @@ def mockserver(session):
263288 )
264289
265290
291+ @nox .session (python = DEFAULT_MOCK_SERVER_TESTS_PYTHON_VERSION )
292+ def mockserver (session ):
293+ # Install all test dependencies, then install this package in-place.
294+
295+ constraints_path = str (
296+ CURRENT_DIRECTORY / "testing" / f"constraints-{ session .python } .txt"
297+ )
298+ # install_unittest_dependencies(session, "-c", constraints_path)
299+ standard_deps = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_DEPENDENCIES
300+ session .install (* standard_deps , "-c" , constraints_path )
301+ session .install ("-e" , "." , "-c" , constraints_path )
302+
303+ # Run py.test against the mockserver tests.
304+ session .run (
305+ "py.test" ,
306+ "--quiet" ,
307+ f"--junitxml=unit_{ session .python } _sponge_log.xml" ,
308+ "--cov=google" ,
309+ "--cov=tests/unit" ,
310+ "--cov-append" ,
311+ "--cov-config=.coveragerc" ,
312+ "--cov-report=" ,
313+ "--cov-fail-under=0" ,
314+ os .path .join ("tests" , "mockserver_tests" ),
315+ * session .posargs ,
316+ )
317+
318+
266319def install_systemtest_dependencies (session , * constraints ):
267320 # Use pre-release gRPC for system tests.
268321 # Exclude version 1.52.0rc1 which has a known issue.
@@ -327,6 +380,17 @@ def system(session, protobuf_implementation, database_dialect):
327380 if os .environ .get ("SPANNER_EMULATOR_HOST" ) and database_dialect == "POSTGRESQL" :
328381 session .skip ("Postgresql is not supported by Emulator yet." )
329382
383+ # Sanity check: Only run tests if the environment variable is set.
384+ if not os .environ .get ("GOOGLE_APPLICATION_CREDENTIALS" , "" ) and not os .environ .get (
385+ "SPANNER_EMULATOR_HOST" , ""
386+ ):
387+ session .skip (
388+ "Credentials or emulator host must be set via environment variable"
389+ )
390+ # If POSTGRESQL tests and Emulator, skip the tests
391+ if os .environ .get ("SPANNER_EMULATOR_HOST" ) and database_dialect == "POSTGRESQL" :
392+ session .skip ("Postgresql is not supported by Emulator yet." )
393+
330394 # Install pyopenssl for mTLS testing.
331395 if os .environ .get ("GOOGLE_API_USE_CLIENT_CERTIFICATE" , "false" ) == "true" :
332396 session .install ("pyopenssl" )
@@ -339,6 +403,12 @@ def system(session, protobuf_implementation, database_dialect):
339403
340404 install_systemtest_dependencies (session , "-c" , constraints_path )
341405
406+ # TODO(https://github.com/googleapis/synthtool/issues/1976):
407+ # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped.
408+ # The 'cpp' implementation requires Protobuf<4.
409+ if protobuf_implementation == "cpp" :
410+ session .install ("protobuf<4" )
411+
342412 # TODO(https://github.com/googleapis/synthtool/issues/1976):
343413 # Remove the 'cpp' implementation once support for Protobuf 3.x is dropped.
344414 # The 'cpp' implementation requires Protobuf<4.
0 commit comments