Skip to content

test_assertion_location #5755

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

Merged
merged 2 commits into from
Aug 17, 2019
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
5 changes: 1 addition & 4 deletions src/_pytest/assertion/rewrite.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
PYC_EXT = ".py" + (__debug__ and "c" or "o")
PYC_TAIL = "." + PYTEST_TAG + PYC_EXT

AST_IS = ast.Is()
AST_NONE = ast.NameConstant(None)


class AssertionRewritingHook:
"""PEP302/PEP451 import hook which rewrites asserts."""
Expand Down Expand Up @@ -857,7 +854,7 @@ def warn_about_none_ast(self, node, module_path, lineno):
internally already.
See issue #3191 for more details.
"""
val_is_none = ast.Compare(node, [AST_IS], [AST_NONE])
val_is_none = ast.Compare(node, [ast.Is()], [ast.NameConstant(None)])
send_warning = ast.parse(
"""\
from _pytest.warning_types import PytestAssertRewriteWarning
Expand Down
32 changes: 27 additions & 5 deletions testing/test_assertion.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,6 @@ def test_frozenzet(self):
assert len(expl) > 1

def test_Sequence(self):

if not hasattr(collections_abc, "MutableSequence"):
pytest.skip("cannot import MutableSequence")
MutableSequence = collections_abc.MutableSequence
Expand Down Expand Up @@ -806,9 +805,6 @@ def test_fmt_multi_newline_before_where(self):


class TestTruncateExplanation:

""" Confirm assertion output is truncated as expected """

# The number of lines in the truncation explanation message. Used
# to calculate that results have the expected length.
LINES_IN_TRUNCATION_MSG = 2
Expand Down Expand Up @@ -969,7 +965,13 @@ def test_hello():
)
result = testdir.runpytest()
result.stdout.fnmatch_lines(
["*def test_hello():*", "*assert x == y*", "*E*Extra items*left*", "*E*50*"]
[
"*def test_hello():*",
"*assert x == y*",
"*E*Extra items*left*",
"*E*50*",
"*= 1 failed in*",
]
)


Expand Down Expand Up @@ -1302,3 +1304,23 @@ def raise_exit(obj):

with pytest.raises(outcomes.Exit, match="Quitting debugger"):
callequal(1, 1)


def test_assertion_location_with_coverage(testdir):
"""This used to report the wrong location when run with coverage (#5754)."""
p = testdir.makepyfile(
"""
def test():
assert False, 1
assert False, 2
"""
)
result = testdir.runpytest(str(p))
result.stdout.fnmatch_lines(
[
"> assert False, 1",
"E AssertionError: 1",
"E assert False",
"*= 1 failed in*",
]
)