Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
18 changes: 18 additions & 0 deletions documentdb_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions documentdb_tests/pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading