Skip to content

Commit

Permalink
Merge pull request #9522 from holmanb/rewrite-test
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus committed Jan 20, 2022
2 parents fe1f0e5 + 3f44b40 commit 4c8fb6f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/9521.improvement.rst
@@ -0,0 +1 @@
Add test coverage to assertion rewrite path.
22 changes: 22 additions & 0 deletions testing/test_assertrewrite.py
Expand Up @@ -1123,6 +1123,28 @@ def test_read_pyc(self, tmp_path: Path) -> None:

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

def test_read_pyc_success(self, tmp_path: Path, pytester: Pytester) -> None:
"""
Ensure that the _rewrite_test() -> _write_pyc() produces a pyc file
that can be properly read with _read_pyc()
"""
from _pytest.assertion import AssertionState
from _pytest.assertion.rewrite import _read_pyc
from _pytest.assertion.rewrite import _rewrite_test
from _pytest.assertion.rewrite import _write_pyc

config = pytester.parseconfig()
state = AssertionState(config, "rewrite")

fn = tmp_path / "source.py"
pyc = Path(str(fn) + "c")

fn.write_text("def test(): assert True")

source_stat, co = _rewrite_test(fn, config)
_write_pyc(state, co, source_stat, pyc)
assert _read_pyc(fn, pyc, state.trace) is not None

def test_read_pyc_more_invalid(self, tmp_path: Path) -> None:
from _pytest.assertion.rewrite import _read_pyc

Expand Down

0 comments on commit 4c8fb6f

Please sign in to comment.