Skip to content

fixtures: fix lineno off-by-one in --fixtures/--fixtures-per-test and a couple of error messages - #15053

Merged
bluetech merged 1 commit into
pytest-dev:mainfrom
bluetech:showfixtures-item-lineno
Sep 17, 2026
Merged

bluetech merged 1 commit into
pytest-dev:mainfrom
bluetech:showfixtures-item-lineno

Conversation

@bluetech

@bluetech bluetech commented Sep 17, 2026

Copy link
Copy Markdown
Member

Fix #15052

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.

@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label 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
bluetech force-pushed the showfixtures-item-lineno branch from 43ce397 to 09d0020 Compare September 17, 2026 12:18
@bluetech

Copy link
Copy Markdown
Member Author

Oops, I had an off-by-one in the issue number :)

@bluetech
bluetech merged commit 56a92c1 into pytest-dev:main Sep 17, 2026
36 checks passed
@bluetech
bluetech deleted the showfixtures-item-lineno branch September 17, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fixtures: --fixtures-per-test has an off-by-one on item's lineno

2 participants