Skip to content

Another way to disable rewrites? #5473

Open
@nedbat

Description

@nedbat

I am trying to add a pytest plugin to coverage.py. Because the plugin is in the coverage package, coverage/init.py will be imported when the plugin is imported. Because I'm using coverage to run pytest in the first place, coverage/__init__.py has already been imported. This leads to a warning:

PytestAssertRewriteWarning: Module already imported so cannot be rewritten: coverage

I can disable this warning by adding PYTEST_DONT_REWRITE to the coverage/__init__.py docstring, but then that word is visible in the docstring for my package. Ugly.

Much of pytest is controlled by specially named attributes in modules. It would be great if I could control rewriting by adding an attribute to my module instead of amending the docstring.

If needed, I can provide a reproducer that shows the warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: enhancementnew feature or API change, should be merged into features branch

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions