Skip to content

Static coverage contexts #689

Open

Description

@tkukushkin

Hi!

I use coverage contexts mainly to distinguish coverage from different tox environments with different python version and sometimes different libraries versions.

coverage.py allows it by adding --context {envname} in tox.ini.
On the other hand, pytest-cov only support dynamic contexts with --cov-context=test.

It would be useful if pytest-cov allowed to set static context name through CLI options.

Activity

  1. webknjaz commented on Apr 21, 2025

    @webknjaz
    Member

    Try setting it in .coveragerc

  2. tkukushkin commented on Apr 21, 2025

    @tkukushkin
    Author

    As far as I understand I can't because it depends on a tox environment name.

  3. added theissue type on Apr 21, 2025
  4. tkukushkin commented on Apr 22, 2025

    @tkukushkin
    Author

    I found a solution: coverage-py supports environment variable substitution in its config.
    So I added the following to .coveragerc:

    context = $COVERAGE_CONTEXT
    

    and to tox.ini:

    setenv =
      COVERAGE_CONTEXT = {envname}
    

    It works as expected. Thank you for your idea.

  5. webknjaz commented on Apr 22, 2025

    @webknjaz
    Member

    Ah, I didn't know it resolves env vars.

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions