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

pytest assertion rewrite slows down all imports. #3918

Closed
fabioz opened this Issue Aug 31, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@fabioz
Contributor

fabioz commented Aug 31, 2018

I've done some profiling and it has shown that using --assert=plain is considerably faster than --assert=rewrite (30% faster in my use case, a real-world scenario with lots of imports).

Using a profiler (http://www.pyvmmonitor.com/) it seems that the slowdown is mostly due to calls to imp.find_module inside of rewrite.AssertionRewritingHook.find_module.

I'll provide a pull request shortly to address this issue by providing an early exit from rewrite.AssertionRewritingHook.find_module when it's certain that a module cannot be rewritten to avoid the imp.find_module call (in my tests, with this change --assert=plain and --assert=rewrite have roughly the same speed).

fabioz added a commit to fabioz/pytest that referenced this issue Aug 31, 2018

fabioz added a commit to fabioz/pytest that referenced this issue Aug 31, 2018

fabioz added a commit to fabioz/pytest that referenced this issue Aug 31, 2018

RonnyPfannschmidt added a commit that referenced this issue Sep 5, 2018

Merge pull request #3919 from fabioz/master
Improve import performance of assertion rewrite. Fixes #3918.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment