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