Skip to content

pytest assertion rewrite slows down all imports. #3918

@fabioz

Description

@fabioz

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: performanceperformance or memory problem/improvement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions