fixtures: fix lineno off-by-one in --fixtures/--fixtures-per-test and a couple of error messages - #15053
Merged
Conversation
RonnyPfannschmidt
approved these changes
Sep 17, 2026
… a couple of error messages `co_firstlineno` is already 1-based, there is no need to +1 it as we do for 0-based linenos. It's possible the +1 was done due to `getlocation` mostly getting used on fixture functions, which are decorated with `@pytest.fixture`. Since `co_firstlineno` points at the first decorator line, the +1 made it point at the actual `def` line. However, this then misses on plain functions like is done in `--fixtures-per-test` for the item functions (which are likely not decorated). We don't currently try to workaround the decorator problem, even the more elaborate `Code`/`getfslineno` code doesn't try to handle it AFAICS. This is just what Python returns, so let's go with it. Fix pytest-dev#15052
bluetech
force-pushed
the
showfixtures-item-lineno
branch
from
September 17, 2026 12:18
43ce397 to
09d0020
Compare
Member
Author
|
Oops, I had an off-by-one in the issue number :) |
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.
Fix #15052
co_firstlinenois already 1-based, there is no need to +1 it as we do for 0-based linenos.It's possible the +1 was done due to
getlocationmostly getting used on fixture functions, which are decorated with@pytest.fixture. Sinceco_firstlinenopoints at the first decorator line, the +1 made it point at the actualdefline. However, this then misses on plain functions like is done in--fixtures-per-testfor the item functions (which are likely not decorated).We don't currently try to workaround the decorator problem, even the more elaborate
Code/getfslinenocode doesn't try to handle it AFAICS. This is just what Python returns, so let's go with it.