Skip to content

Reload does not work with assertion rewritten modules #3539

@iwanb

Description

@iwanb

Importing a module with assertion rewrite enabled, changing the code and then reloading the module (with reload or imp.reload) does not pick up the changes.

A fix was done in 2.7.0 but AFAIK it is wrong:
https://docs.pytest.org/en/latest/changelog.html#id456
In _pytest/assertion/rewrite.py, load_module should indeed use the module from sys.modules, but it should also load the code again (overwriting the module dict):
https://docs.python.org/3/library/importlib.html#importlib.abc.Loader.load_module

I wrote a testcase and a possible fix here (but I'm not that familiar with the code):
iwanb@c78569b

I can do a pull request if it looks ok to you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: rewriterelated to the assertion rewrite mechanismtype: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions