Skip to content

Commit 05bfe73

Browse files
committed
Fix wrong location of assertion error with coverage.py
Reverts using-constant part from 39ba996. Fixes #5754.
1 parent c3a8e60 commit 05bfe73

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/_pytest/assertion/rewrite.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@
3333
PYC_EXT = ".py" + (__debug__ and "c" or "o")
3434
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT
3535

36-
AST_IS = ast.Is()
37-
AST_NONE = ast.NameConstant(None)
38-
3936

4037
class AssertionRewritingHook:
4138
"""PEP302/PEP451 import hook which rewrites asserts."""
@@ -857,7 +854,7 @@ def warn_about_none_ast(self, node, module_path, lineno):
857854
internally already.
858855
See issue #3191 for more details.
859856
"""
860-
val_is_none = ast.Compare(node, [AST_IS], [AST_NONE])
857+
val_is_none = ast.Compare(node, [ast.Is()], [ast.NameConstant(None)])
861858
send_warning = ast.parse(
862859
"""\
863860
from _pytest.warning_types import PytestAssertRewriteWarning

testing/test_assertion.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,3 +1302,23 @@ def raise_exit(obj):
13021302

13031303
with pytest.raises(outcomes.Exit, match="Quitting debugger"):
13041304
callequal(1, 1)
1305+
1306+
1307+
def test_assertion_location_with_coverage(testdir):
1308+
"""This used to report the wrong location when run with coverage (#5754)."""
1309+
p = testdir.makepyfile(
1310+
"""
1311+
def test():
1312+
assert False, 1
1313+
assert False, 2
1314+
"""
1315+
)
1316+
result = testdir.runpytest(str(p))
1317+
result.stdout.fnmatch_lines(
1318+
[
1319+
"> assert False, 1",
1320+
"E AssertionError: 1",
1321+
"E assert False",
1322+
"*= 1 failed in*",
1323+
]
1324+
)

0 commit comments

Comments
 (0)