Skip to content

Commit d4acf6f

Browse files
committed
tests(spanner): update prerelease_deps nox session to match system tests
1 parent f03d376 commit d4acf6f

1 file changed

Lines changed: 75 additions & 18 deletions

File tree

packages/google-cloud-spanner/noxfile.py

Lines changed: 75 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,12 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
655655
system_test_path = os.path.join("tests", "system.py")
656656
system_test_folder_path = os.path.join("tests", "system")
657657

658+
system_test_exists = os.path.exists(system_test_path)
659+
system_test_folder_exists = os.path.exists(system_test_folder_path)
660+
# Sanity check: only run tests if found.
661+
if not system_test_exists and not system_test_folder_exists:
662+
session.skip("System tests were not found")
663+
658664
if os.environ.get("SPANNER_EMULATOR_HOST"):
659665
# Run tests against the emulator
660666
run_system = True
@@ -675,24 +681,75 @@ def prerelease_deps(session, protobuf_implementation, database_dialect):
675681
run_system = False
676682

677683
if run_system:
678-
# Run the tests (deduplicated logic)
679-
test_path = (
680-
system_test_path
681-
if os.path.exists(system_test_path)
682-
else system_test_folder_path
683-
)
684-
session.run(
685-
"py.test",
686-
"--verbose",
687-
f"--junitxml=system_{session.python}_sponge_log.xml",
688-
test_path,
689-
*session.posargs,
690-
env={
691-
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
692-
"SPANNER_DATABASE_DIALECT": database_dialect,
693-
"SKIP_BACKUP_TESTS": "true",
694-
},
695-
)
684+
# Run py.test against the system tests.
685+
if system_test_exists:
686+
args = [
687+
"py.test",
688+
"--quiet",
689+
"-o",
690+
"asyncio_mode=auto",
691+
f"--junitxml=system_{session.python}_sponge_log.xml",
692+
]
693+
if not session.posargs:
694+
args.append(system_test_path)
695+
args.extend(session.posargs)
696+
697+
session.run(
698+
*args,
699+
env={
700+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
701+
"SPANNER_DATABASE_DIALECT": database_dialect,
702+
"SKIP_BACKUP_TESTS": "true",
703+
},
704+
)
705+
elif system_test_folder_exists:
706+
# Run sync tests
707+
sync_args = [
708+
"py.test",
709+
"--quiet",
710+
"-o",
711+
"asyncio_mode=auto",
712+
f"--junitxml=system_{session.python}_sync_sponge_log.xml",
713+
]
714+
if not session.posargs:
715+
sync_args.append(os.path.join("tests", "system"))
716+
sync_args.append("--ignore=tests/system/_async")
717+
else:
718+
sync_args.extend(session.posargs)
719+
720+
session.run(
721+
*sync_args,
722+
env={
723+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
724+
"SPANNER_DATABASE_DIALECT": database_dialect,
725+
"SKIP_BACKUP_TESTS": "true",
726+
},
727+
)
728+
729+
# Run async tests
730+
async_args = [
731+
"py.test",
732+
"--quiet",
733+
"-o",
734+
"asyncio_mode=auto",
735+
f"--junitxml=system_{session.python}_async_sponge_log.xml",
736+
]
737+
if not session.posargs:
738+
async_args.append(os.path.join("tests", "system", "_async"))
739+
else:
740+
# If posargs are provided, only run if they match async tests
741+
# or just skip if they were already run in sync.
742+
# For simplicity, we only run async folder if no posargs.
743+
return
744+
745+
session.run(
746+
*async_args,
747+
env={
748+
"PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION": protobuf_implementation,
749+
"SPANNER_DATABASE_DIALECT": database_dialect,
750+
"SKIP_BACKUP_TESTS": "true",
751+
},
752+
)
696753

697754

698755
@nox.session(python=ALL_PYTHON)

0 commit comments

Comments
 (0)