4040SYSTEM_TEST_PYTHON_VERSIONS : List [str ] = ["3.12" ]
4141
4242UNIT_TEST_PYTHON_VERSIONS : List [str ] = [
43+ "3.8" ,
4344 "3.9" ,
4445 "3.10" ,
4546 "3.11" ,
4647 "3.12" ,
4748 "3.13" ,
4849 "3.14" ,
4950]
51+
52+ ALL_PYTHON = list (UNIT_TEST_PYTHON_VERSIONS )
53+ ALL_PYTHON .extend (["3.7" ])
5054UNIT_TEST_STANDARD_DEPENDENCIES = [
5155 "mock" ,
5256 "asyncmock" ,
9498 "docs" ,
9599 "docfx" ,
96100 "format" ,
101+ "prerelease_deps" ,
102+ "core_deps_from_source" ,
103+ "mypy" ,
97104]
98105
99106# Error if a python version is missing
@@ -213,7 +220,7 @@ def install_unittest_dependencies(session, *constraints):
213220 session .run ("pip" , "list" )
214221
215222
216- @nox .session (python = UNIT_TEST_PYTHON_VERSIONS )
223+ @nox .session (python = ALL_PYTHON )
217224@nox .parametrize (
218225 "protobuf_implementation" ,
219226 ["python" , "upb" , "cpp" ],
@@ -576,6 +583,14 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
576583 ):
577584 session .skip ("cpp implementation is not supported in python 3.11+" )
578585
586+ # Sanity check: Only run tests if credentials or emulator are set.
587+ if not os .environ .get ("GOOGLE_APPLICATION_CREDENTIALS" , "" ) and not os .environ .get (
588+ "SPANNER_EMULATOR_HOST" , ""
589+ ):
590+ session .skip (
591+ "Credentials or emulator host must be set via environment variable"
592+ )
593+
579594 # Install all dependencies
580595 session .install ("-e" , ".[all, tests, tracing]" )
581596 unit_deps_all = UNIT_TEST_STANDARD_DEPENDENCIES + UNIT_TEST_EXTERNAL_DEPENDENCIES
@@ -656,7 +671,6 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
656671 system_test_path = os .path .join ("tests" , "system.py" )
657672 system_test_folder_path = os .path .join ("tests" , "system" )
658673
659- < << << << HEAD
660674 if os .environ .get ("SPANNER_EMULATOR_HOST" ):
661675 # Run tests against the emulator
662676 run_system = True
@@ -665,36 +679,16 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
665679 if os .environ .get ("GOOGLE_APPLICATION_CREDENTIALS" ):
666680 run_system = True
667681 else :
668- < << << << HEAD
669- session .log (
670- "Skipping system tests because GOOGLE_APPLICATION_CREDENTIALS is not set"
671- )
672- run_system = False
673- else :
674- # Skip to speed up build (only run python implementation on real Spanner)
675- session .log (
676- f"Skipping system tests for protobuf={ protobuf_implementation } on real Spanner to speed up build"
677- )
678- == == == =
679682 session .log ("Skipping system tests because GOOGLE_APPLICATION_CREDENTIALS is not set" )
680683 run_system = False
681684 else :
682685 # Skip to speed up build (only run python implementation on real Spanner)
683686 session .log (f"Skipping system tests for protobuf={ protobuf_implementation } on real Spanner to speed up build" )
684- >> >> >> > d4bff6eaee2 (chore : improves logic within prerelease_deps session )
685687 run_system = False
686688
687689 if run_system :
688690 # Run the tests (deduplicated logic)
689- < << << << HEAD
690- test_path = (
691- system_test_path
692- if os .path .exists (system_test_path )
693- else system_test_folder_path
694- )
695- == == == =
696691 test_path = system_test_path if os .path .exists (system_test_path ) else system_test_folder_path
697- >> >> >> > d4bff6eaee2 (chore : improves logic within prerelease_deps session )
698692 session .run (
699693 "py.test" ,
700694 "--verbose" ,
@@ -707,11 +701,6 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
707701 "SKIP_BACKUP_TESTS" : "true" ,
708702 },
709703 )
710- < << << << HEAD
711-
712- == == == =
713- >> >> >> > d4bff6eaee2 (chore : improves logic within prerelease_deps session )
714- == == == =
715704 # Only run system tests for one protobuf implementation on real Spanner to speed up the build.
716705 if os .environ .get ("SPANNER_EMULATOR_HOST" ) or protobuf_implementation == "python" :
717706 # Sanity check: Only run system tests if credentials or emulator are set.
@@ -745,50 +734,41 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
745734 )
746735 else :
747736 session .log ("Skipping system tests because credentials/emulator are missing" )
748- > >> >> >> 3 cda3a846be (chore : refine prerelease_deps to conditionally run system tests )
749-
750- @nox .session (python = DEFAULT_PYTHON_VERSION )
751- def mypy (session ):
752- """Run the type checker."""
753- session .skip ("Mypy is not yet supported" )
754-
755- # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579):
756- # use the latest version of mypy
757- session .install (
758- "mypy<1.16.0" ,
759- "types-requests" ,
760- "types-protobuf" ,
761- )
762- session .install ("." )
763- session .run (
764- "mypy" ,
765- "-p" ,
766- "google" ,
767- #"--check-untyped-defs",
768- * session .posargs ,
769- )
737+ # Only run system tests if found.
738+ if os .path .exists (system_test_path ):
739+ session .run (
740+ "py.test" ,
741+ "--verbose" ,
742+ f"--junitxml=system_{ session .python } _sponge_log.xml" ,
743+ system_test_path ,
744+ * session .posargs ,
745+ env = {
746+ "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" : protobuf_implementation ,
747+ "SPANNER_DATABASE_DIALECT" : database_dialect ,
748+ "SKIP_BACKUP_TESTS" : "true" ,
749+ },
750+ )
751+ elif os .path .exists (system_test_folder_path ):
752+ session .run (
753+ "py.test" ,
754+ "--verbose" ,
755+ f"--junitxml=system_{ session .python } _sponge_log.xml" ,
756+ system_test_folder_path ,
757+ * session .posargs ,
758+ env = {
759+ "PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION" : protobuf_implementation ,
760+ "SPANNER_DATABASE_DIALECT" : database_dialect ,
761+ "SKIP_BACKUP_TESTS" : "true" ,
762+ },
763+ )
770764
771765
772- @nox .session (python = ALL_PYTHON )
766+ @nox .session (python = DEFAULT_PYTHON_VERSION )
773767def mypy (session ):
774768 """Run the type checker."""
775- # TODO(https://github.com/googleapis/gapic-generator-python/issues/2579):
776- # use the latest version of mypy
777- session .install (
778- "mypy<1.16.0" ,
779- "types-requests" ,
780- "types-protobuf" ,
781- )
782- session .install ("." )
783- session .run (
784- "mypy" ,
785- "-p" ,
786- "google" ,
787- "--check-untyped-defs" ,
788- * session .posargs ,
789- )
790-
791-
769+ # TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
770+ # Add mypy tests
771+ session .skip ("mypy tests are not yet supported" )
792772
793773@nox .session (python = DEFAULT_PYTHON_VERSION )
794774def core_deps_from_source (session ):
@@ -798,34 +778,3 @@ def core_deps_from_source(session):
798778 # TODO(https://github.com/googleapis/google-cloud-python/issues/16014):
799779 # Add core deps from source tests
800780 session .skip ("Core deps from source tests are not yet supported" )
801-
802- @nox .session
803- def format (session : nox .sessions .Session ) -> None :
804- """
805- Run ruff to sort imports and format code.
806- """
807- # 1. Install ruff (skipped automatically if you run with --no-venv)
808- session .install (RUFF_VERSION )
809-
810- # 2. Run Ruff to fix imports
811- # check --select I: Enables strict import sorting
812- # --fix: Applies the changes automatically
813- session .run (
814- "ruff" ,
815- "check" ,
816- "--select" ,
817- "I" ,
818- "--fix" ,
819- f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
820- "--line-length=88" , # Standard Black line length
821- * LINT_PATHS ,
822- )
823-
824- # 3. Run Ruff to format code
825- session .run (
826- "ruff" ,
827- "format" ,
828- f"--target-version=py{ ALL_PYTHON [0 ].replace ('.' , '' )} " ,
829- "--line-length=88" , # Standard Black line length
830- * LINT_PATHS ,
831- )
0 commit comments