New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nicoddemus opened this Issue Sep 15, 2016 · 3 comments

Comments

Projects
None yet
2 participants
@nicoddemus
Member

nicoddemus commented Sep 15, 2016

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

@nicoddemus

This comment has been minimized.

Member

nicoddemus commented Sep 15, 2016

Investigating further, I found that in development mode there's the SOURCES.txt metadata, but not RECORD. 😞

Perhaps we should just try both RECORD and SOURCES.txt then?

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Sep 15, 2016

we might want add a general tool to do ahead of time assert rewriting and mark all plugin as always being rewritten

@RonnyPfannschmidt

This comment has been minimized.

Member

RonnyPfannschmidt commented Sep 15, 2016

(so that we can opt out of always marking them)

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