Skip to content

FEAT: support running coverage measurements through coverage.py directly, instead of via pytest-cov #330

Open

Description

@neutrinoceros

I discovered this while helping on #207, but the issue I want to report is actually quite orthogonal to that PR, so I'm opening this ticket separately.

In short, I would like to make pytest-cov a choice rather than a hard requirement for coverage reporting; this plugin is merely more than a middle man and provides no actual functionality on its own, so I would like to eliminate it from dependency graphs to reduce the "attack surface" (not exclusively, but also in the security sense) for dependees.

Running coverage directly isn't really challenging in itself, it should be as simple as the following substitution:

pytest ... --cov --cov-report=xml
coverage run  --parallel-mode -m pytest
coverage combine
coverage xml

Note that, by virtue of coverage being a hard dependency to pytest-cov, it would be perfectly backwards compatible to use it directly.

The difficulty lies in how to approach this; here's a summary of the design constraints we're facing.

  • tox.yml (via tox itself) can only append arguments to a command via matrix.pytest_flag, which tox redirects as posargs
  • in order to automatically form a coverage command dynamically, I need to be able to prepend coverage run -m before the pytest invoke
  • I would also need to somehow be able to add dynamically generated commands to invoke coverage combine or coverage xml ...

This just seems impossible to do in the most general case. My preferred solution would be to renounce doing this stuff dynamically and let users define their own commands (using pytest-cov or coverage directly, at their discretion); but of course that'd be a breaking change. I will try to come up with a backward compatible transition plan.

Originally posted by @neutrinoceros in #207 (comment)

Activity

  1. AryaBhatt45 commented on Nov 20, 2025

    @AryaBhatt45
  2. neutrinoceros commented on Nov 20, 2025

    @neutrinoceros
    Author
  3. AryaBhatt45 commented on Nov 21, 2025

    @AryaBhatt45
  4. neutrinoceros commented on Nov 21, 2025

    @neutrinoceros
    Author
  5. AryaBhatt45 commented on Nov 22, 2025

    @AryaBhatt45
  6. neutrinoceros commented on Nov 22, 2025

    @neutrinoceros
    Author
  7. Flamki commented on Feb 18, 2026

    @Flamki
  8. saksham242007 commented on Feb 24, 2026

    @saksham242007
  9. reopened this on Mar 24, 2026
  10. Cadair commented on Mar 24, 2026

    @Cadair
    Member

    The backwards compatible-ness of this related to #383.

    Although, I'm in the camp of it's not worth making things more complex for the sake of removing pytest-cov.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions