Materialize product() passed to parametrize (pytest 9.1 compat)#5244
Open
jaraco wants to merge 4 commits into
Open
Materialize product() passed to parametrize (pytest 9.1 compat)#5244jaraco wants to merge 4 commits into
jaraco wants to merge 4 commits into
Conversation
A one-shot iterator (itertools.product) passed to @pytest.mark.parametrize gets exhausted after the first of this class' test methods collects, so the rest are silently skipped. pytest 9.1 deprecates this (pytest-dev/pytest#13409, PytestRemovedIn10Warning), turning it into a collection error. Wrap it in list() so the values can be reused. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Replace the inline list(product(...)) with a module-level greedy_product = compose(list, product), documenting the pytest 9.1 re-iterable-Collection requirement (pytest-dev/pytest#13409) as its docstring. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
|
Tick the box to add this pull request to the merge queue (same as
|
Member
Author
|
mypy checks are failing with: |
compose(list, product) can't be typed: product is an overloaded callable, and passing it by value to compose's Callable[_P, _R] parameter collapses it to its first overload (single iterable), so mypy types the result as a one-arg function (var-annotated / arg-type / too-many-arguments errors). Define greedy_product as a function that *calls* product(*iterables) instead, so the variadic overload resolves normally and the helper types cleanly. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
Author
|
Claude says python/mypy#15737 and python/mypy#13540 are precisely relevant. |
Revert greedy_product to the concise compose(list, product) form. mypy can't type it (product is overloaded; passing it by value through compose's ParamSpec collapses it to its first overload, python/mypy#13540), so suppress the resulting var-annotated/arg-type/call-arg errors with type: ignore comments that cite the upstream issue. warn_unused_ignores is disabled in mypy.ini, so these are safe. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
setuptools/tests/test_config_discovery.py::TestDiscoverPackagesAndPyModules::test_purposefully_emptypasses anitertools.product(a one-shot iterator) directly asargvaluesto@pytest.mark.parametrize.pytest 9.1 deprecates non-Collection iterables for
argvalues(PytestRemovedIn10Warning), which surfaces here as an error during collection — taking the wholetest_config_discovery.pymodule down with it. The class-level decorator is exactly the hazard the deprecation targets: a bare iterator is exhausted after the first test method collects, silently skipping the rest.See pytest-dev/pytest#13409 and the deprecation note.
Fix
Render the product eager via a small documented helper:
so
argvaluesis a re-iterablelist. The rationale lives in the helper's docstring.jaraco.functoolsis already a setuptools test dependency, so no new requirement.Verification
test_purposefully_emptynow collects and passes (30 params).ruff check+ruff format --checkclean.Note: this only manifests with pytest >= 9.1; CI on an older pytest won't have flagged it yet, so this is a forward-compat fix.
🤖 Generated with Claude Code