Skip to content

Commit b66899d

Browse files
authored
Merge pull request #9530 from nicoddemus/backport-9522
2 parents b1b1bd0 + 6a1b8e4 commit b66899d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

changelog/9521.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add test coverage to assertion rewrite path.

testing/test_assertrewrite.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,28 @@ def test_read_pyc(self, tmp_path: Path) -> None:
11231123

11241124
assert _read_pyc(source, pyc) is None # no error
11251125

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+
11261148
@pytest.mark.skipif(
11271149
sys.version_info < (3, 7), reason="Only the Python 3.7 format for simplicity"
11281150
)

0 commit comments

Comments
 (0)