Skip to content

Handle dead code in tests folders of the repo #15803

Open
@webknjaz

Description

Problem statement

While reviewing #15772, the discussions led to re-discovering the observation that not all lines in the tests folders are hit in CI. This effectively means that there's dead code in there.

End goal / acceptance criteria

Guidance

There are several reasons for lines not being marked as covered, and different situations may need different approaches.

  • A function or a fixture that is never used anywhere. Solution: delete it.
    • Sometimes, a test function is copied and not renamed. When this happens, the first copy has all of its lines uncovered because it's shadowed by the new function. Solution: rename one of the functions, so both are actually executed.
  • A Python module that is never used anywhere. Solution: delete it.
  • Code that is only hit when testing goes wrong, this is often under a branch in the control flow. Solution: append a # pragma: no cover to the line. Be granular, add a code comment justifying the exclusion as these lines will stop influencing the coverage metric forever, being never taken into account.
  • Part of tests is run conditionally and is supposed to remain in the repo. Solution: add the corresponding invocation in CI. Alternative (undesired): make the test runner omit coverage collection in .coveragerc.

Locating the affected files

The test files with dead code can be found by browsing these web pages:

Justification / reading materials

When there's dead test code, it goes stale after some while. It becomes broken while contributing to a false sense of test existence. We don't want this.

N.B. I posted more on how coverage is set up in general, here: #15772 (comment).

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions