r/Python • • 22d ago

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

30 Upvotes

163 comments sorted by

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:

  • a test function missing its test_ prefix, so pytest never collects it
  • a second def test_x in the same file, which silently replaces the first
  • an assert placed after the raising call inside a with pytest.raises(...) block, which never runs

The 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.raises blocks. 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