Skip to content

Commit 16f2893

Browse files
hroncokfrenzymadness
authored andcommitted
Skip tests for missing Pythons much faster
As a side effect, report the stringified .pyc path as test parameter id.
1 parent f0f9c50 commit 16f2893

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

test.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,32 @@ def fixed_filename(original_filename):
1717
return original_filename.with_suffix(".fixed" + original_filename.suffix)
1818

1919

20+
def param(p, *, skip_reason=None):
21+
"""Return a pytest.param with stringified id, for nicer verbose output
22+
23+
When skip_reson is set, the pytest.param will be marked as skipped."""
24+
if skip_reason is None:
25+
return pytest.param(p, id=str(p))
26+
return pytest.param(p,
27+
id=str(p),
28+
marks=[pytest.mark.skip(reason=skip_reason)])
29+
30+
2031
def generate_test_data():
21-
yield from (Path("test") / "python_stdlib").glob("**/*.pyc")
22-
yield from (Path("test") / "pure_marshal").glob("*")
23-
yield from (Path("test") / "renamed_pycs").glob("*")
32+
for python_version_dir in (Path("test") / "python_stdlib").glob("*"):
33+
python_version = python_version_dir.name
34+
try:
35+
check_call(("python" + python_version, "-c", "pass"))
36+
except FileNotFoundError:
37+
skip_reason = f"python{python_version} not found"
38+
else:
39+
skip_reason = None
40+
yield from (
41+
param(p, skip_reason=skip_reason)
42+
for p in python_version_dir.glob("*.pyc")
43+
)
44+
yield from (param(p) for p in (Path("test") / "pure_marshal").glob("*"))
45+
yield from (param(p) for p in (Path("test") / "renamed_pycs").glob("*"))
2446

2547

2648
@pytest.mark.parametrize("original_filename", generate_test_data())
@@ -71,6 +93,7 @@ def test_complete(original_filename, tmp_path):
7193
try:
7294
check_call(CHECK_CMD)
7395
except FileNotFoundError:
96+
# this could still happen with test/renamed_pycs
7497
pytest.skip(
7598
f"python{python_version_str} not found! Cannot check the result."
7699
)

0 commit comments

Comments
 (0)