Skip to content

Commit a232b65

Browse files
authored
PYTHON-4613 Skip async tests when testing eventlet/gevent (mongodb#1780)
1 parent 2afbd4b commit a232b65

File tree

7 files changed

+35
-12
lines changed

7 files changed

+35
-12
lines changed

green_framework_test.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,18 @@ def run(framework_name, *args):
6060
# Monkey-patch.
6161
FRAMEWORKS[framework_name]()
6262

63+
arg_list = list(args)
64+
65+
# Never run async tests with a framework
66+
if len(arg_list) <= 1:
67+
arg_list.extend(["-m", "not default_async and default"])
68+
else:
69+
for i in range(len(arg_list) - 1):
70+
if "-m" in arg_list[i]:
71+
arg_list[i + 1] = f"not default_async and {arg_list[i + 1]}"
72+
6373
# Run the tests.
64-
sys.exit(pytest.main(list(args)))
74+
sys.exit(pytest.main(arg_list))
6575

6676

6777
def main():

hatch.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ features = ["test"]
4141
[envs.test.scripts]
4242
test = "pytest -v --durations=5 --maxfail=10 {args}"
4343
test-eg = "bash ./.evergreen/run-tests.sh {args}"
44-
test-async = "test test/asynchronous/ {args}"
44+
test-async = "pytest -v --durations=5 --maxfail=10 -m default_async {args}"
4545
test-mockupdb = ["pip install -U git+https://github.com/ajdavis/mongo-mockup-db@master", "test -m mockupdb"]
4646

4747
[envs.encryption]

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ zstd = ["requirements/zstd.txt"]
7070

7171
[tool.pytest.ini_options]
7272
minversion = "7"
73-
addopts = ["-ra", "--strict-config", "--strict-markers", "--junitxml=xunit-results/TEST-results.xml", "-m default"]
73+
addopts = ["-ra", "--strict-config", "--strict-markers", "--junitxml=xunit-results/TEST-results.xml", "-m default or default_async"]
7474
testpaths = ["test"]
7575
log_cli_level = "INFO"
7676
faulthandler_timeout = 1500
@@ -108,6 +108,7 @@ markers = [
108108
"load_balancer: load balancer tests",
109109
"mockupdb: tests that rely on mockupdb",
110110
"default: default test suite",
111+
"default_async: default async test suite",
111112
]
112113

113114
[tool.mypy]

test/asynchronous/conftest.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
from test import pytest_conf
34
from test.asynchronous import async_setup, async_teardown
45

56
import pytest_asyncio
@@ -14,7 +15,4 @@ async def test_setup_and_teardown():
1415
await async_teardown()
1516

1617

17-
def pytest_collection_modifyitems(items, config):
18-
for item in items:
19-
if not any(item.iter_markers()):
20-
item.add_marker("default")
18+
pytest_collection_modifyitems = pytest_conf.pytest_collection_modifyitems

test/conftest.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from test import setup, teardown
3+
from test import pytest_conf, setup, teardown
44

55
import pytest
66

@@ -14,7 +14,4 @@ def test_setup_and_teardown():
1414
teardown()
1515

1616

17-
def pytest_collection_modifyitems(items, config):
18-
for item in items:
19-
if not any(item.iter_markers()):
20-
item.add_marker("default")
17+
pytest_collection_modifyitems = pytest_conf.pytest_collection_modifyitems

test/pytest_conf.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from __future__ import annotations
2+
3+
4+
def pytest_collection_modifyitems(items, config):
5+
sync_items = []
6+
async_items = [
7+
item
8+
for item in items
9+
if "asynchronous" in item.fspath.dirname or sync_items.append(item) # type: ignore[func-returns-value]
10+
]
11+
for item in async_items:
12+
if not any(item.iter_markers()):
13+
item.add_marker("default_async")
14+
for item in sync_items:
15+
if not any(item.iter_markers()):
16+
item.add_marker("default")

tools/synchro.py

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"aclose": "close",
9696
"async-transactions-ref": "transactions-ref",
9797
"async-snapshot-reads-ref": "snapshot-reads-ref",
98+
"default_async": "default",
9899
}
99100

100101
docstring_replacements: dict[tuple[str, str], str] = {

0 commit comments

Comments
 (0)