Skip to content

Wrap product() in list() where passed to parametrize#380

Merged
jab merged 1 commit into
jab:mainfrom
Sanjays2402:fix/parametrize-non-collection-iterable
Jul 7, 2026
Merged

Wrap product() in list() where passed to parametrize#380
jab merged 1 commit into
jab:mainfrom
Sanjays2402:fix/parametrize-non-collection-iterable

Conversation

@Sanjays2402

Copy link
Copy Markdown
Contributor

What

Two tests pass an itertools.product object directly to
@pytest.mark.parametrize:

  • tests/test_bidict.py::test_eq_and_or_with_non_mapping
  • tests/test_bidict.py::test_putall_matches_bulk_put

product(...) returns a one-shot iterator, not a Collection. This
change wraps both in list() so the argvalues are a concrete
Collection.

Why

Starting with pytest 9.1, passing a non-Collection iterable to
parametrize raises PytestRemovedIn10Warning, and pytest 10 removes
support entirely
— at which point collecting tests/test_bidict.py
will fail. See the pytest deprecation note:
https://docs.pytest.org/en/stable/deprecations.html#parametrize-iterators

Today (pytest 8.x/9.x) the suite still collects, but the run already
emits the warning:

PytestRemovedIn10Warning: Passing a non-Collection iterable to parametrize is deprecated.
  Test: tests/test_bidict.py::test_eq_and_or_with_non_mapping, argvalues type: product
  Test: tests/test_bidict.py::test_putall_matches_bulk_put, argvalues type: product

Reproduce (deterministic)

Promote the warning to an error exactly as pytest 10 will:

$ python -m pytest tests/ -W "error::pytest.PytestRemovedIn10Warning"
E   pytest.PytestRemovedIn10Warning: Passing a non-Collection iterable to parametrize is deprecated.
E   Test: tests/test_bidict.py::test_eq_and_or_with_non_mapping, argvalues type: product
ERROR tests/test_bidict.py - pytest.PytestRemovedIn10Warning: ...
!!!!! Interrupted: 1 error during collection !!!!!
1 error in 0.09s

Before / after

before (product(...)) after (list(product(...)))
pytest -W error::pytest.PytestRemovedIn10Warning ERROR at collection 114 passed
default pytest run 2 PytestRemovedIn10Warning 0 warnings

Notes

test_eq_and_or_with_non_mapping and test_putall_matches_bulk_put pass an
itertools.product object directly to @pytest.mark.parametrize. product
returns a one-shot iterator, not a Collection. pytest 9.1 emits
PytestRemovedIn10Warning for non-Collection iterables passed to
parametrize, and pytest 10 removes support entirely, so collection of
the whole test module will error once pytest is upgraded.

Materialize the argvalues with list(), matching the existing
list(powerset(product(...))) usage in this module. No behavioral change
to the parametrization today; this only makes the argvalues a concrete
Collection so the tests keep collecting under pytest >= 10.
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Benchmark report

✅ No threshold-triggering regressions detected.

  • Baseline asset: GHA-linux-cachegrind-x86_64-CPython-3.14-baseline.json
  • Threshold: min:5%
  • Result: no threshold-triggering regressions detected
  • Run: benchmark workflow run

This benchmark check is informational and does not block merging.

@jab
jab merged commit 23d307c into jab:main Jul 7, 2026
8 checks passed
@jab

jab commented Jul 7, 2026

Copy link
Copy Markdown
Owner

Thanks for the contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants