@@ -1028,74 +1028,36 @@ def test_read_pyc(self, tmpdir):
1028
1028
1029
1029
assert _read_pyc (str (source ), str (pyc )) is None # no error
1030
1030
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
+ """
1037
1035
[pytest]
1038
1036
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)
1054
1037
"""
1055
1038
)
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 = """
1064
1041
def reloaded():
1065
1042
return False
1066
1043
1067
1044
def rewrite_self():
1068
1045
with open(__file__, 'w') as self:
1069
1046
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
+ """ ,
1083
1048
test_fun = """
1084
1049
import sys
1085
- try:
1086
- from imp import reload
1087
- except ImportError:
1088
- pass
1050
+ from importlib import reload
1089
1051
1090
1052
def test_loader():
1091
1053
import file
1092
1054
assert not file.reloaded()
1093
1055
file.rewrite_self()
1094
- reload(file)
1056
+ assert sys.modules["file"] is reload(file)
1095
1057
assert file.reloaded()
1096
- """
1058
+ """ ,
1097
1059
)
1098
- result = testdir .runpytest ("-s" )
1060
+ result = testdir .runpytest ()
1099
1061
result .stdout .fnmatch_lines (["* 1 passed*" ])
1100
1062
1101
1063
def test_get_data_support (self , testdir ):
0 commit comments