diff --git a/green_framework_test.py b/green_framework_test.py index 65025798c..037d0279c 100644 --- a/green_framework_test.py +++ b/green_framework_test.py @@ -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(): diff --git a/hatch.toml b/hatch.toml index 25d113e5d..8b1cf93e3 100644 --- a/hatch.toml +++ b/hatch.toml @@ -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] diff --git a/pyproject.toml b/pyproject.toml index cfd994f56..4380b57e8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] diff --git a/test/asynchronous/conftest.py b/test/asynchronous/conftest.py index 398ba4265..f5bcd953a 100644 --- a/test/asynchronous/conftest.py +++ b/test/asynchronous/conftest.py @@ -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 diff --git a/test/conftest.py b/test/conftest.py index 39d29355b..431dd152f 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -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 diff --git a/test/pytest_conf.py b/test/pytest_conf.py new file mode 100644 index 000000000..75f3e7432 --- /dev/null +++ b/test/pytest_conf.py @@ -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") diff --git a/tools/synchro.py b/tools/synchro.py index e0af50229..5711e1f84 100644 --- a/tools/synchro.py +++ b/tools/synchro.py @@ -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] = {