@@ -1123,6 +1123,28 @@ def test_read_pyc(self, tmp_path: Path) -> None:
1123
1123
1124
1124
assert _read_pyc (source , pyc ) is None # no error
1125
1125
1126
+ def test_read_pyc_success (self , tmp_path : Path , pytester : Pytester ) -> None :
1127
+ """
1128
+ Ensure that the _rewrite_test() -> _write_pyc() produces a pyc file
1129
+ that can be properly read with _read_pyc()
1130
+ """
1131
+ from _pytest .assertion import AssertionState
1132
+ from _pytest .assertion .rewrite import _read_pyc
1133
+ from _pytest .assertion .rewrite import _rewrite_test
1134
+ from _pytest .assertion .rewrite import _write_pyc
1135
+
1136
+ config = pytester .parseconfig ()
1137
+ state = AssertionState (config , "rewrite" )
1138
+
1139
+ fn = tmp_path / "source.py"
1140
+ pyc = Path (str (fn ) + "c" )
1141
+
1142
+ fn .write_text ("def test(): assert True" )
1143
+
1144
+ source_stat , co = _rewrite_test (fn , config )
1145
+ _write_pyc (state , co , source_stat , pyc )
1146
+ assert _read_pyc (fn , pyc , state .trace ) is not None
1147
+
1126
1148
def test_read_pyc_more_invalid (self , tmp_path : Path ) -> None :
1127
1149
from _pytest .assertion .rewrite import _read_pyc
1128
1150
0 commit comments