Skip to content

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

@neutrinoceros

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)

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