Skip to content

Commit 7db0c79

Browse files
committed
fix: Prevent test_aio.py collection errors on Python 3.7
Add pytest_ignore_collect hook to skip test_aio.py entirely on Python 3.7 to prevent ImportError during test collection. The previous approach using only pytest_collection_modifyitems was too late in the process - the error occurred when pytest tried to import the module before skip markers could be applied. Both hooks are marked as safe to remove when Python 3.7 support is dropped.
1 parent 4a52a07 commit 7db0c79

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

conftest.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,20 @@ def isolate_logging():
4444
reload(logging)
4545

4646

47+
# Safe to remove when we drop Python 3.7 support
48+
def pytest_ignore_collect(path, config):
49+
"""Ignore async test files on Python 3.7 since Starlette requires Python 3.8+"""
50+
if sys.version_info >= (3, 8):
51+
return False
52+
53+
# Skip test_aio.py entirely on Python 3.7
54+
if path.basename == "test_aio.py":
55+
return True
56+
57+
return False
58+
59+
60+
# Safe to remove when we drop Python 3.7 support
4761
def pytest_collection_modifyitems(config, items):
4862
"""Skip async-related tests on Python 3.7 since Starlette requires Python 3.8+"""
4963
if sys.version_info >= (3, 8):
@@ -76,7 +90,7 @@ def pytest_collection_modifyitems(config, items):
7690
test_file = str(item.fspath)
7791
test_name = item.name
7892

79-
# Skip tests in async-specific test files
93+
# Skip tests in async-specific test files (backup for any not caught by ignore)
8094
if "test_aio" in test_file:
8195
skip_test = True
8296

0 commit comments

Comments
 (0)