Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.0.x] Merge pull request #9522 from holmanb/rewrite-test #9530

Merged
merged 1 commit into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/9521.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add test coverage to assertion rewrite path.
22 changes: 22 additions & 0 deletions testing/test_assertrewrite.py
Original file line number Diff line number Diff line change
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

@pytest.mark.skipif(
sys.version_info < (3, 7), reason="Only the Python 3.7 format for simplicity"
)
Expand Down