Skip to content

Commit b0393cc

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 b0393cc

File tree

1 file changed

+12
-49
lines changed

1 file changed

+12
-49
lines changed

testing/test_assertrewrite.py

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from _pytest.assertion.rewrite import rewrite_asserts
2424
from _pytest.config import ExitCode
2525
from _pytest.pathlib import Path
26+
from _pytest.pytester import Testdir
2627

2728

2829
def setup_module(mod):
@@ -1040,74 +1041,36 @@ def test_read_pyc(self, tmpdir):
10401041

10411042
assert _read_pyc(str(source), str(pyc)) is None # no error
10421043

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-
"""
1044+
def test_reload_is_same_and_reloads(self, testdir: Testdir) -> None:
1045+
"""Reloading a (collected) module after change picks up the change."""
1046+
testdir.makeini(
1047+
"""
10491048
[pytest]
10501049
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)
10661050
"""
10671051
)
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-
"""
1052+
testdir.makepyfile(
1053+
file="""
10761054
def reloaded():
10771055
return False
10781056
10791057
def rewrite_self():
10801058
with open(__file__, 'w') as self:
10811059
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(
1060+
""",
10951061
test_fun="""
10961062
import sys
1097-
try:
1098-
from imp import reload
1099-
except ImportError:
1100-
pass
1063+
from importlib import reload
11011064
11021065
def test_loader():
11031066
import file
11041067
assert not file.reloaded()
11051068
file.rewrite_self()
1106-
reload(file)
1069+
assert sys.modules["file"] is reload(file)
11071070
assert file.reloaded()
1108-
"""
1071+
""",
11091072
)
1110-
result = testdir.runpytest("-s")
1073+
result = testdir.runpytest()
11111074
result.stdout.fnmatch_lines(["* 1 passed*"])
11121075

11131076
def test_get_data_support(self, testdir):

0 commit comments

Comments
 (0)