Skip to content

Commit 646a970

Browse files
committed
tests: revisit tests for removed load_module
The tests came via c629f6b and c61ff31. 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.
1 parent 2d9dac9 commit 646a970

File tree

1 file changed

+11
-49
lines changed

1 file changed

+11
-49
lines changed

testing/test_assertrewrite.py

Lines changed: 11 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,74 +1040,36 @@ def test_read_pyc(self, tmpdir):
10401040

10411041
assert _read_pyc(str(source), str(pyc)) is None # no error
10421042

1043-
def test_reload_is_same(self, testdir):
1044-
# A file that will be picked up during collecting.
1045-
testdir.tmpdir.join("file.py").ensure()
1046-
testdir.tmpdir.join("pytest.ini").write(
1047-
textwrap.dedent(
1048-
"""
1043+
def test_reload_is_same_and_reloads(self, testdir: Testdir) -> None:
1044+
"""Reloading a (collected) module after change picks up the change."""
1045+
testdir.makeini(
1046+
"""
10491047
[pytest]
10501048
python_files = *.py
1051-
"""
1052-
)
1053-
)
1054-
1055-
testdir.makepyfile(
1056-
test_fun="""
1057-
import sys
1058-
try:
1059-
from imp import reload
1060-
except ImportError:
1061-
pass
1062-
1063-
def test_loader():
1064-
import file
1065-
assert sys.modules["file"] is reload(file)
10661049
"""
10671050
)
1068-
result = testdir.runpytest("-s")
1069-
result.stdout.fnmatch_lines(["* 1 passed*"])
1070-
1071-
def test_reload_reloads(self, testdir):
1072-
"""Reloading a module after change picks up the change."""
1073-
testdir.tmpdir.join("file.py").write(
1074-
textwrap.dedent(
1075-
"""
1051+
testdir.makepyfile(
1052+
file="""
10761053
def reloaded():
10771054
return False
10781055
10791056
def rewrite_self():
10801057
with open(__file__, 'w') as self:
10811058
self.write('def reloaded(): return True')
1082-
"""
1083-
)
1084-
)
1085-
testdir.tmpdir.join("pytest.ini").write(
1086-
textwrap.dedent(
1087-
"""
1088-
[pytest]
1089-
python_files = *.py
1090-
"""
1091-
)
1092-
)
1093-
1094-
testdir.makepyfile(
1059+
""",
10951060
test_fun="""
10961061
import sys
1097-
try:
1098-
from imp import reload
1099-
except ImportError:
1100-
pass
1062+
from importlib import reload
11011063
11021064
def test_loader():
11031065
import file
11041066
assert not file.reloaded()
11051067
file.rewrite_self()
1106-
reload(file)
1068+
assert sys.modules["file"] is reload(file)
11071069
assert file.reloaded()
1108-
"""
1070+
""",
11091071
)
1110-
result = testdir.runpytest("-s")
1072+
result = testdir.runpytest()
11111073
result.stdout.fnmatch_lines(["* 1 passed*"])
11121074

11131075
def test_get_data_support(self, testdir):

0 commit comments

Comments
 (0)