fix: point file and line at the same place - #6
Merged
Merged
Conversation
They came from different sources. `file` from report.location, `line` from
reprcrash.lineno, and reprcrash points at the frame that raised. For
`self.assertEqual` that frame is inside the standard library, so a run of
unittest tests reported this:
{"file":"test_auth.py","line":918,"type":"AssertionError","message":"401 != 200"}
in a file of twelve lines. A coordinate that does not exist, and the
library exists to hand an agent somewhere to look.
Bare `assert` hid it: the crash lands in the test file, so file and line
happen to agree and every test we had passed. It shows up with unittest,
with any project that wraps its assertions in a helper, and with
pyssertive.
Both now come from the last entry of the rendered traceback, which is the
`path:lineno:` pytest itself prints, already relative and already 1-based,
and a pair by construction. Verified to match pytest exactly across bare
assert, unittest assertEqual, a helper in the same file, a raise and a
fixture error, in serial and under -n 2.
Falls back to reprcrash when there is no traceback to read (--tb=no,
--tb=line, --tb=native), and to the test file with line 0 when a plugin
has replaced longrepr with a plain string. Both tiers still return a pair.
86 tests, coverage still 100%.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



fileandlinecould point at different places, because they came from different sources:filefromreport.location,linefromreprcrash.lineno.reprcrashpoints at the frame that raised, which forself.assertEqualis inside the standard library. A run of unittest tests reported this:{"file":"test_auth.py","line":918,"type":"AssertionError","message":"401 != 200"}in a file of twelve lines. The coordinate does not exist, and handing an agent somewhere to look is what this library is for.
Why no test caught it
Every failure in the suite used a bare
assert, where the crash lands in the test file itself, so the two sources happen to agree. It shows up withunittest.TestCase, with any project that wraps its assertions in a helper, and with pyssertive.Found by checking whether
pymmary[pytest]covers unittest projects, which it does, except the line numbers were wrong.The fix
Both fields now come from the last entry of the rendered traceback, which is what pytest prints as
path:lineno:. It is already relative, already 1-based, and it is a pair by construction. It is also the frame the ecosystem points at: assertion helpers that set__tracebackhide__drop out, so the last entry lands back in the test.Measured against real pytest output, all five shapes, serial and
-n 2:unittestassertEqualtest_mix.py:11case.py:918test_mix.py:11asserttest_mix.py:15test_mix.py:15test_mix.py:15test_mix.py:6test_mix.py:6test_mix.py:6raisetest_mix.py:23test_mix.py:23test_mix.py:23test_mix.py:28test_mix.py:28test_mix.py:28reprfilelocsurvives the xdist worker boundary, so-n 2gives the same numbers.Fallbacks
Two, both returning a coherent pair:
--tb=no,--tb=line,--tb=native): falls back toreprcrash, paying an absolute path for it.longreprreplaced by a plain string, which plugins are allowed to do: falls back to the test file with line 0. Losing the line is acceptable, crashing is not.86 tests, coverage still 100%.