r/Python • u/AutoModerator • 22d ago
Showcase Showcase Thread
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
30
Upvotes
r/Python • u/AutoModerator • 22d ago
Post all of your code/projects/showcases/AI slop here.
Recycles once a month.
View all comments
1
u/dylanpulver 8d ago
dead-tests: find pytest tests that never run or can never fail
What My Project Does
It scans a repo for tests that stay green because they never execute. In Python that's three shapes:
test_prefix, so pytest never collects itdef test_xin the same file, which silently replaces the firstassertplaced after the raising call inside awith pytest.raises(...)block, which never runsThe Python checks parse the syntax tree. Each one is a single stdlib-only file.
Target Audience
Anyone maintaining a pytest suite, especially an older one. It runs with Docker or as a GitHub Action that only flags files a PR changes.
Comparison
Ruff covers two of these if you turn the rules on: F811 for redefinitions and PT012 for multi-statement
pytest.raisesblocks. Neither is in the default set, and the projects below still had these shapes. Nothing I found flags a test function that pytest won't collect. dead-tests also runs the same kind of checks for Java, Kotlin, C#, PHP, Ruby, Go, Rust and JS. I ran it on pydantic, fsspec and cbor2 and the fixes merged upstream: pydantic#13921, pydantic#14201, filesystem_spec#2192, cbor2#363. In cbor2, all six dead assertions expected messages the library stopped emitting in 6.0.Repo: github.com/dylanpulver/dead-tests. Write-up with the details: The tests that pass because they never run