Skip to content

rewrite does not work automatically for plugins in develop mode #1934

Closed
@nicoddemus

Description

@nicoddemus

pytest-mock uses pytest's assert introspection to enrich the error message when one of the standard mock.assert* methods fail. Those asserts are in the plugin module (pytest_mock.py), and while they are rewritten just fine when installed from a package, they don't get rewritten in development mode (python setup.py develop).

I tracked down the problem to our code which tries to rewrite all modules of installed plugins in config.py, function _consider_importhook:

self.pluginmanager.rewrite_hook = hook
for entrypoint in pkg_resources.iter_entry_points('pytest11'):
    for entry in entrypoint.dist._get_metadata('RECORD'):
        fn = entry.split(',')[0]
        ...

When in development mode, entrypoint.dist._get_metadata('RECORD') returns an empty list; digging into that method I noticed it tries to access EGG metadata. Being in development mode, there's no EGG meta-data, so it makes sense.

I think the only solution is to move the function which needs assertion rewriting to its own "util" module and call register_assert_rewrite before importing it (which is no big deal).

Any other ideas on how to fix/workaround it?

cc @flub

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