From dfdf73bd3ecd5d03589da8d1e9a7ed6e4dde8063 Mon Sep 17 00:00:00 2001 From: PatersonProjects Date: Tue, 16 Jun 2026 13:50:10 -0700 Subject: [PATCH] Add a skip localhost mark to conditionally skip the destructive shutdown command Signed-off-by: PatersonProjects --- .../commands/shutdown/test_smoke_shutdown.py | 2 +- documentdb_tests/conftest.py | 18 ++++++++++++++++++ documentdb_tests/pytest.ini | 1 + 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/documentdb_tests/compatibility/tests/system/administration/commands/shutdown/test_smoke_shutdown.py b/documentdb_tests/compatibility/tests/system/administration/commands/shutdown/test_smoke_shutdown.py index 5385d8ec2..c29b6b8f3 100644 --- a/documentdb_tests/compatibility/tests/system/administration/commands/shutdown/test_smoke_shutdown.py +++ b/documentdb_tests/compatibility/tests/system/administration/commands/shutdown/test_smoke_shutdown.py @@ -9,7 +9,7 @@ from documentdb_tests.framework.assertions import assertFailure from documentdb_tests.framework.executor import execute_admin_command -pytestmark = pytest.mark.smoke +pytestmark = [pytest.mark.smoke, pytest.mark.skip_localhost] def test_smoke_shutdown(collection): diff --git a/documentdb_tests/conftest.py b/documentdb_tests/conftest.py index b88a99733..8292f57ef 100644 --- a/documentdb_tests/conftest.py +++ b/documentdb_tests/conftest.py @@ -207,6 +207,8 @@ def pytest_collection_modifyitems(session, config, items): Or run them manually with: pytest -m no_parallel -p no:xdist Tests marked 'replica_set' are skipped when the server is not a replica set member. + + Tests marked 'skip_localhost' are skipped when connected to a localhost server. """ # Skip replica_set tests when not connected to a replica set conn_str = getattr(config, "connection_string", "") or "" @@ -227,6 +229,22 @@ def pytest_collection_modifyitems(session, config, items): ) ) + # Skip skip_localhost tests when connected to a localhost server + try: + from pymongo.uri_parser import parse_uri + + localhost_hosts = {"localhost", "127.0.0.1", "::1"} + nodes = parse_uri(conn_str)["nodelist"] if conn_str else [] + is_localhost = any(host in localhost_hosts for host, _ in nodes) + except Exception: + is_localhost = False + if is_localhost: + for item in items: + if item.get_closest_marker("skip_localhost"): + item.add_marker( + pytest.mark.skip(reason="skipped on localhost (server connection is local)") + ) + # Deselect no_parallel tests when running under xdist is_xdist = bool(getattr(config.option, "numprocesses", None)) or hasattr(config, "workerinput") if is_xdist: diff --git a/documentdb_tests/pytest.ini b/documentdb_tests/pytest.ini index de4799073..63219b817 100644 --- a/documentdb_tests/pytest.ini +++ b/documentdb_tests/pytest.ini @@ -45,6 +45,7 @@ markers = engine_xcrash(engine, reason): test crashes the server on a specific engine no_parallel: Tests that must run sequentially (not in parallel) replica_set: Tests that need to run on replica set + skip_localhost: Tests skipped when connected to a localhost server # Timeout for tests (seconds) timeout = 300