PYTHON-4613 Skip async tests when testing eventlet/gevent (#1780)

This commit is contained in:
Noah Stapp 2024-08-12 10:23:43 -07:00 committed by GitHub
parent 2afbd4b279
commit a232b657d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 35 additions and 12 deletions

View File

@ -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():

View File

@ -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]

View File

@ -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
@ -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]

View File

@ -1,5 +1,6 @@
from __future__ import annotations
from test import pytest_conf
from test.asynchronous import async_setup, async_teardown
import pytest_asyncio
@ -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

View File

@ -1,6 +1,6 @@
from __future__ import annotations
from test import setup, teardown
from test import pytest_conf, setup, teardown
import pytest
@ -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
test/pytest_conf.py Normal file
View File

@ -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")

View File

@ -95,6 +95,7 @@ replacements = {
"aclose": "close",
"async-transactions-ref": "transactions-ref",
"async-snapshot-reads-ref": "snapshot-reads-ref",
"default_async": "default",
}
docstring_replacements: dict[tuple[str, str], str] = {