Skip to content

Commit

Permalink
PYTHON-4613 Skip async tests when testing eventlet/gevent (#1780)
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahStapp authored Aug 12, 2024
1 parent 2afbd4b commit a232b65
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 12 deletions.
12 changes: 11 additions & 1 deletion green_framework_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,18 @@ def run(framework_name, *args):
# Monkey-patch.
FRAMEWORKS[framework_name]()

arg_list = list(args)

# Never run async tests with a framework
if len(arg_list) <= 1:
arg_list.extend(["-m", "not default_async and default"])
else:
for i in range(len(arg_list) - 1):
if "-m" in arg_list[i]:
arg_list[i + 1] = f"not default_async and {arg_list[i + 1]}"

# Run the tests.
sys.exit(pytest.main(list(args)))
sys.exit(pytest.main(arg_list))


def main():
Expand Down
2 changes: 1 addition & 1 deletion hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ features = ["test"]
[envs.test.scripts]
test = "pytest -v --durations=5 --maxfail=10 {args}"
test-eg = "bash ./.evergreen/run-tests.sh {args}"
test-async = "test test/asynchronous/ {args}"
test-async = "pytest -v --durations=5 --maxfail=10 -m default_async {args}"
test-mockupdb = ["pip install -U git+https://github.com/ajdavis/mongo-mockup-db@master", "test -m mockupdb"]

[envs.encryption]
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ zstd = ["requirements/zstd.txt"]

[tool.pytest.ini_options]
minversion = "7"
addopts = ["-ra", "--strict-config", "--strict-markers", "--junitxml=xunit-results/TEST-results.xml", "-m default"]
addopts = ["-ra", "--strict-config", "--strict-markers", "--junitxml=xunit-results/TEST-results.xml", "-m default or default_async"]
testpaths = ["test"]
log_cli_level = "INFO"
faulthandler_timeout = 1500
Expand Down Expand Up @@ -108,6 +108,7 @@ markers = [
"load_balancer: load balancer tests",
"mockupdb: tests that rely on mockupdb",
"default: default test suite",
"default_async: default async test suite",
]

[tool.mypy]
Expand Down
6 changes: 2 additions & 4 deletions test/asynchronous/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

from test import pytest_conf
from test.asynchronous import async_setup, async_teardown

import pytest_asyncio
Expand All @@ -14,7 +15,4 @@ async def test_setup_and_teardown():
await async_teardown()


def pytest_collection_modifyitems(items, config):
for item in items:
if not any(item.iter_markers()):
item.add_marker("default")
pytest_collection_modifyitems = pytest_conf.pytest_collection_modifyitems
7 changes: 2 additions & 5 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from test import setup, teardown
from test import pytest_conf, setup, teardown

import pytest

Expand All @@ -14,7 +14,4 @@ def test_setup_and_teardown():
teardown()


def pytest_collection_modifyitems(items, config):
for item in items:
if not any(item.iter_markers()):
item.add_marker("default")
pytest_collection_modifyitems = pytest_conf.pytest_collection_modifyitems
16 changes: 16 additions & 0 deletions test/pytest_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from __future__ import annotations


def pytest_collection_modifyitems(items, config):
sync_items = []
async_items = [
item
for item in items
if "asynchronous" in item.fspath.dirname or sync_items.append(item) # type: ignore[func-returns-value]
]
for item in async_items:
if not any(item.iter_markers()):
item.add_marker("default_async")
for item in sync_items:
if not any(item.iter_markers()):
item.add_marker("default")
1 change: 1 addition & 0 deletions tools/synchro.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"aclose": "close",
"async-transactions-ref": "transactions-ref",
"async-snapshot-reads-ref": "snapshot-reads-ref",
"default_async": "default",
}

docstring_replacements: dict[tuple[str, str], str] = {
Expand Down

0 comments on commit a232b65

Please sign in to comment.