Skip to content

Commit 18bc706

Browse files
blueyedasottile
authored andcommitted
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 abbd97f commit 18bc706

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
@@ -1028,74 +1028,36 @@ def test_read_pyc(self, tmpdir):
10281028

10291029
assert _read_pyc(str(source), str(pyc)) is None # no error
10301030

1031-
def test_reload_is_same(self, testdir):
1032-
# A file that will be picked up during collecting.
1033-
testdir.tmpdir.join("file.py").ensure()
1034-
testdir.tmpdir.join("pytest.ini").write(
1035-
textwrap.dedent(
1036-
"""
1031+
def test_reload_is_same_and_reloads(self, testdir: Testdir) -> None:
1032+
"""Reloading a (collected) module after change picks up the change."""
1033+
testdir.makeini(
1034+
"""
10371035
[pytest]
10381036
python_files = *.py
1039-
"""
1040-
)
1041-
)
1042-
1043-
testdir.makepyfile(
1044-
test_fun="""
1045-
import sys
1046-
try:
1047-
from imp import reload
1048-
except ImportError:
1049-
pass
1050-
1051-
def test_loader():
1052-
import file
1053-
assert sys.modules["file"] is reload(file)
10541037
"""
10551038
)
1056-
result = testdir.runpytest("-s")
1057-
result.stdout.fnmatch_lines(["* 1 passed*"])
1058-
1059-
def test_reload_reloads(self, testdir):
1060-
"""Reloading a module after change picks up the change."""
1061-
testdir.tmpdir.join("file.py").write(
1062-
textwrap.dedent(
1063-
"""
1039+
testdir.makepyfile(
1040+
file="""
10641041
def reloaded():
10651042
return False
10661043
10671044
def rewrite_self():
10681045
with open(__file__, 'w') as self:
10691046
self.write('def reloaded(): return True')
1070-
"""
1071-
)
1072-
)
1073-
testdir.tmpdir.join("pytest.ini").write(
1074-
textwrap.dedent(
1075-
"""
1076-
[pytest]
1077-
python_files = *.py
1078-
"""
1079-
)
1080-
)
1081-
1082-
testdir.makepyfile(
1047+
""",
10831048
test_fun="""
10841049
import sys
1085-
try:
1086-
from imp import reload
1087-
except ImportError:
1088-
pass
1050+
from importlib import reload
10891051
10901052
def test_loader():
10911053
import file
10921054
assert not file.reloaded()
10931055
file.rewrite_self()
1094-
reload(file)
1056+
assert sys.modules["file"] is reload(file)
10951057
assert file.reloaded()
1096-
"""
1058+
""",
10971059
)
1098-
result = testdir.runpytest("-s")
1060+
result = testdir.runpytest()
10991061
result.stdout.fnmatch_lines(["* 1 passed*"])
11001062

11011063
def test_get_data_support(self, testdir):

0 commit comments

Comments
 (0)