Skip to content

Commit

Permalink
fix: improved pytest check
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Sep 22, 2022
1 parent 5a89eed commit 32bb98e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executing/executing.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ def compile_similar_to(source, matching_code):

def is_rewritten_by_pytest(code):
return any(
bc.opname.startswith("LOAD_") and isinstance(bc.argval,str) and bc.argval.startswith("@py_assert")
bc.opname != "LOAD_CONST" and isinstance(bc.argval,str) and bc.argval.startswith("@py")
for bc in get_instructions(code)
)

Expand Down
10 changes: 10 additions & 0 deletions tests/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,13 @@ def test_no_pytest_rewrite():
# no assert -> no rewrite
if is_rewritten_by_pytest(frame.f_code):
raise AssertionError("unexpected pytest assert rewrite")

def test_no_pytest_rewrite_with_consts():
frame=inspect.currentframe()

# LOAD_CONST "@py_assert..." should not trigger a false positive
a="@py_assert..."

# no assert -> no rewrite
if is_rewritten_by_pytest(frame.f_code):
raise AssertionError("unexpected pytest assert rewrite")

0 comments on commit 32bb98e

Please sign in to comment.