Skip to content

fixtures: fix incorrect "duplicate parametrization" when using indirect=[...]#13976

Merged
bluetech merged 3 commits into
pytest-dev:mainfrom
bluetech:duplicate-parametrization-fix
Nov 20, 2025
Merged

fixtures: fix incorrect "duplicate parametrization" when using indirect=[...]#13976
bluetech merged 3 commits into
pytest-dev:mainfrom
bluetech:duplicate-parametrization-fix

Conversation

@bluetech

Copy link
Copy Markdown
Member

The code in _get_direct_parametrize_args only handled indirect=True/False, it didn't account for indirect=[...]. This caused the added test to start failing after d56b1af.

Fix by using the common _resolve_args_directness function. It's a bit heavy for the task but correctness first...

Fix #13974.

I am not marking for backport because the bug was laying dormant for a while and only uncovered by d56b1af which is only in main, not yet released.

@bluetech bluetech added the skip news used on prs to opt out of the changelog requirement label Nov 17, 2025
@braingram

braingram commented Nov 17, 2025

Copy link
Copy Markdown

I tested this with the downstream test suite which lead to #13974 and with this PR the tests are back to passing. Thanks for the quick fix!
https://github.com/asdf-format/asdf/actions/runs/19445301685/job/55638606133?pr=1990#step:10:113

The function name is ambiguous, full nodeid is more helpful.
…ect=[...]`

The code in `_get_direct_parametrize_args` only handled
`indirect=True/False`, it didn't account for `indirect=[...]`. This
caused the added test to start failing after
d56b1af.

Fix by using the common `_resolve_args_directness` function. It's a bit
heavy for the task but correctness first...

Fix pytest-dev#13974.
@bluetech bluetech force-pushed the duplicate-parametrization-fix branch from 48d3478 to adcdeb9 Compare November 18, 2025 20:02

@Zac-HD Zac-HD left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

@bluetech bluetech merged commit 6b6502e into pytest-dev:main Nov 20, 2025
33 checks passed
@bluetech bluetech deleted the duplicate-parametrization-fix branch November 20, 2025 15:00
@dmakhno

dmakhno commented Jun 15, 2026

Copy link
Copy Markdown

Hi @bluetech ,

Cannot find anything in changelog to 9.1.0 like compatibility change.
Just to acknowledge this is expect now behaviour

import pytest

DEFAULT = ["a", "b", "c"]

@pytest.fixture(params=DEFAULT)
def target(request):
    return request.param

@pytest.mark.parametrize(
    "target",
    ["a", "b"],  # override default
    indirect=True,
)
def test_foo(target):
    assert True

which used to work on 9.0.3 (the motivation fixture in conftest has default), is causing duplicate parametrization of 'target' on 9.1.0

And must be fixed using pytest_generate_tests, making "target" parametless.

@pytest.fixture
def target(request):
    return request.param

def pytest_generate_tests(self, metafunc: Metafunc) -> None:
    if not_missing_default(metafunc):  # function that iter_markers("parametrize") and its args
        return
    metafunc.parametrize('target', DEFAULT, indirect=True)

Like https://github.com/datachain-ai/datachain/pull/1818/changes

@bluetech

Copy link
Copy Markdown
Member Author

@dmakhno Please see #14591, will be fixed in 9.1.1 which we'll hopefully release this weekend.

henryiii added a commit to scikit-build/scikit-build-core that referenced this pull request Jun 16, 2026
🤖 _AI text below_ 🤖

## Problem

pytest 9.1.0 shipped a regression
([pytest-dev/pytest#13974](pytest-dev/pytest#13974),
fixed upstream in
[#13976](pytest-dev/pytest#13976), landing in
9.1.1) where overriding a `params=`-fixture via
`@pytest.mark.parametrize(..., indirect=True)` raises `duplicate
parametrization` at collection time.

Because our config sets `filterwarnings = ["error"]` and these surface
as collection errors, the suite hard-fails on the three tests that
override the `editable` fixture (defined with `params=[None, "redirect",
"inplace"]` in `tests/conftest.py`):

- `test_editable.py::test_cython_pxd`
- `test_editable_generated.py::test_generated_files`
- `test_pyproject_pep660.py::test_pep660_wheel`

## Fix

Pin `pytest >=7.2,!=9.1.0` in the `test-core` dependency group. The
exclusion is narrow: 9.1.1+ (with the upstream fix) is allowed once
released. No test code changes needed.

Verified collection is clean (622 tests, no errors) with the pin
applied.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip news used on prs to opt out of the changelog requirement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"duplicate parametrization" errors with pytest dev

5 participants