Skip to content

How to programmatically disable coverage? #418

@jaraco

Description

@jaraco

I'd like to be able to programmatically disable coverage tests based on some runtime condition. In particular, on Setuptools, when running tests against PyPy, enabling coverage is prohibitively expensive (~3x run time). I'd like to be able to enable coverage tests by default, but when PyPy is detected (probably in conftest.py), disable the coverage.

I'd like to enable coverage by default by setting [pytest] addopts=--cov, but have that not take effect when running on PyPy. I've tried using tox functionality to secondarily disable by passing --no-cov, but even tox can't detect when PyPy is running; it can only detect when an environment named pypy or pypy3 is indicated, but sometimes, tox is invoked from within PyPy, so the env name is py or python, but the interpreter is still PyPy.

Is there a way within conftest to disable the coverage behavior based on arbitrary Python logic? What incantations would be necessary at what hook point to disable coverage? Thanks!

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