Fix reload() with modules handled via python_files

If a module exists in `sys.modules` already, `load_module` has to return it.

Fixes https://bitbucket.org/pytest-dev/pytest/issue/435

--HG--
branch : fix-reload
This commit is contained in:
Daniel Hahler
2015-03-04 16:21:27 +01:00
parent 41e6b04f0b
commit c629f6b18b
2 changed files with 30 additions and 0 deletions

View File

@@ -146,6 +146,12 @@ class AssertionRewritingHook(object):
return self
def load_module(self, name):
# If there is an existing module object named 'fullname' in
# sys.modules, the loader must use that existing module. (Otherwise,
# the reload() builtin will not work correctly.)
if name in sys.modules:
return sys.modules[name]
co, pyc = self.modules.pop(name)
# I wish I could just call imp.load_compiled here, but __file__ has to
# be set properly. In Python 3.2+, this all would be handled correctly