tests: revisit tests for removed load_module

The tests came via c629f6b18 and c61ff31ffa.
The fixes from there are kind of obsoleted by 4cd08f9 (moving to importlib),
but it makes sense to keep them as integration tests in general.
This commit is contained in:
Daniel Hahler 2020-04-02 15:25:53 +02:00 committed by Anthony Sottile
parent abbd97f917
commit 18bc706fdc
1 changed files with 11 additions and 49 deletions

View File

@ -1028,74 +1028,36 @@ class TestAssertionRewriteHookDetails:
assert _read_pyc(str(source), str(pyc)) is None # no error assert _read_pyc(str(source), str(pyc)) is None # no error
def test_reload_is_same(self, testdir): def test_reload_is_same_and_reloads(self, testdir: Testdir) -> None:
# A file that will be picked up during collecting. """Reloading a (collected) module after change picks up the change."""
testdir.tmpdir.join("file.py").ensure() testdir.makeini(
testdir.tmpdir.join("pytest.ini").write(
textwrap.dedent(
""" """
[pytest] [pytest]
python_files = *.py python_files = *.py
""" """
) )
)
testdir.makepyfile( testdir.makepyfile(
test_fun=""" file="""
import sys
try:
from imp import reload
except ImportError:
pass
def test_loader():
import file
assert sys.modules["file"] is reload(file)
"""
)
result = testdir.runpytest("-s")
result.stdout.fnmatch_lines(["* 1 passed*"])
def test_reload_reloads(self, testdir):
"""Reloading a module after change picks up the change."""
testdir.tmpdir.join("file.py").write(
textwrap.dedent(
"""
def reloaded(): def reloaded():
return False return False
def rewrite_self(): def rewrite_self():
with open(__file__, 'w') as self: with open(__file__, 'w') as self:
self.write('def reloaded(): return True') self.write('def reloaded(): return True')
""" """,
)
)
testdir.tmpdir.join("pytest.ini").write(
textwrap.dedent(
"""
[pytest]
python_files = *.py
"""
)
)
testdir.makepyfile(
test_fun=""" test_fun="""
import sys import sys
try: from importlib import reload
from imp import reload
except ImportError:
pass
def test_loader(): def test_loader():
import file import file
assert not file.reloaded() assert not file.reloaded()
file.rewrite_self() file.rewrite_self()
reload(file) assert sys.modules["file"] is reload(file)
assert file.reloaded() assert file.reloaded()
""" """,
) )
result = testdir.runpytest("-s") result = testdir.runpytest()
result.stdout.fnmatch_lines(["* 1 passed*"]) result.stdout.fnmatch_lines(["* 1 passed*"])
def test_get_data_support(self, testdir): def test_get_data_support(self, testdir):