diff --git a/pyproject.toml b/pyproject.toml index 33322c43a5..4bf3928f95 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -424,6 +424,7 @@ exclude = [ "^fixtures/", "^logs/", "^site/", + "^tests/json_infra/fixtures/", ] plugins = ["pydantic.mypy"] diff --git a/tests/json_infra/conftest.py b/tests/json_infra/conftest.py index 7c3bae1171..143591a8de 100644 --- a/tests/json_infra/conftest.py +++ b/tests/json_infra/conftest.py @@ -80,6 +80,7 @@ def pytest_addoption(parser: Parser) -> None: type=str, help="Run tests from and including the specified fork.", ) + parser.addoption( "--until", action="store", @@ -88,6 +89,7 @@ def pytest_addoption(parser: Parser) -> None: type=str, help="Run tests until and including the specified fork.", ) + parser.addoption( "--fork", action="store", @@ -95,6 +97,7 @@ def pytest_addoption(parser: Parser) -> None: default="", help="Only run tests for the specified fork.", ) + parser.addoption( "--file-list", action="store", @@ -106,6 +109,13 @@ def pytest_addoption(parser: Parser) -> None: ), ) + parser.addoption( + "--tests-file", + dest="tests_path", + type=Path, + help="Path to a file containing test ids, one per line", + ) + def pytest_configure(config: Config) -> None: """ @@ -175,6 +185,29 @@ def pytest_configure(config: Config) -> None: config.stash[desired_forks_key] = desired_forks +def pytest_collection_modifyitems(config: Config, items: list[Item]) -> None: + """Filter test items.""" + tests_path = config.getoption("tests_path", None) + if tests_path is None: + return + + with open(tests_path) as f: + test_ids = set(x.removesuffix("\n") for x in f.readlines()) + + selected = [] + deselected = [] + for item in items: + if item.nodeid in test_ids: + selected.append(item) + test_ids.remove(item.nodeid) + else: + deselected.append(item) + + if deselected: + config.hook.pytest_deselected(items=deselected) + items[:] = selected # keep only what matches + + class _FixturesDownloader: cache: Final[SQLiteCache] session: Final[CachedSession] diff --git a/tox.ini b/tox.ini index 0983dd466d..e67cc3a4b4 100644 --- a/tox.ini +++ b/tox.ini @@ -39,6 +39,7 @@ commands = pytest \ -n auto --maxprocesses 6 \ --basetemp="{temp_dir}/pytest" \ + {posargs} \ src [testenv:tests_pytest_pypy3] @@ -57,6 +58,7 @@ commands = pytest \ -n auto --maxprocesses 6 \ --basetemp="{temp_dir}/pytest" \ + {posargs} \ src [testenv:json_infra] @@ -85,6 +87,7 @@ commands = --log-to "{toxworkdir}/logs" \ --clean \ --until Osaka \ + {posargs} \ tests [testenv:pypy3] @@ -108,6 +111,7 @@ commands = --log-to "{toxworkdir}/logs" \ --clean \ --until Osaka \ + {posargs} \ tests [testenv:benchmark] @@ -123,6 +127,7 @@ commands = --log-to "{toxworkdir}/logs" \ --clean \ --fork Prague \ + {posargs} \ tests/benchmark [testenv:optimized] @@ -137,6 +142,7 @@ commands = --ignore-glob='tests/test_t8n.py' \ --basetemp="{temp_dir}/pytest" \ --optimized \ + {posargs} \ tests/json_infra [testenv:spec-docs]