|
23 | 23 | from _pytest.assertion.rewrite import rewrite_asserts
|
24 | 24 | from _pytest.config import ExitCode
|
25 | 25 | from _pytest.pathlib import Path
|
| 26 | +from _pytest.pytester import Testdir |
26 | 27 |
|
27 | 28 |
|
28 | 29 | def setup_module(mod):
|
@@ -1040,74 +1041,36 @@ def test_read_pyc(self, tmpdir):
|
1040 | 1041 |
|
1041 | 1042 | assert _read_pyc(str(source), str(pyc)) is None # no error
|
1042 | 1043 |
|
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 | + """ |
1049 | 1048 | [pytest]
|
1050 | 1049 | 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) |
1066 | 1050 | """
|
1067 | 1051 | )
|
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=""" |
1076 | 1054 | def reloaded():
|
1077 | 1055 | return False
|
1078 | 1056 |
|
1079 | 1057 | def rewrite_self():
|
1080 | 1058 | with open(__file__, 'w') as self:
|
1081 | 1059 | 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 | + """, |
1095 | 1061 | test_fun="""
|
1096 | 1062 | import sys
|
1097 |
| - try: |
1098 |
| - from imp import reload |
1099 |
| - except ImportError: |
1100 |
| - pass |
| 1063 | + from importlib import reload |
1101 | 1064 |
|
1102 | 1065 | def test_loader():
|
1103 | 1066 | import file
|
1104 | 1067 | assert not file.reloaded()
|
1105 | 1068 | file.rewrite_self()
|
1106 |
| - reload(file) |
| 1069 | + assert sys.modules["file"] is reload(file) |
1107 | 1070 | assert file.reloaded()
|
1108 |
| - """ |
| 1071 | + """, |
1109 | 1072 | )
|
1110 |
| - result = testdir.runpytest("-s") |
| 1073 | + result = testdir.runpytest() |
1111 | 1074 | result.stdout.fnmatch_lines(["* 1 passed*"])
|
1112 | 1075 |
|
1113 | 1076 | def test_get_data_support(self, testdir):
|
|
0 commit comments