Move selection before repeat#99
Open
CanYing0913 wants to merge 1 commit into
Open
Conversation
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.
TL;DR
fix #15 #21 #95
Motivation
pytest-repeatcurrently implements repetition by adding an indirect parameter inpytest_generate_tests. As a result, pytest createsoriginal item count × repeat countitems before collection filtering and otherpytest_collection_modifyitemshooks run.For large suites and high repeat counts, this multiplies collection work even for tests that will later be deselected. In real-world cases, collection can take more than an hour while the selected tests themselves only take a few minutes.
What changed
This PR moves repeat expansion until after collection modification and deselection have completed:
-k,-m, and other collection filtering/reordering plugins to the original items.--countor@pytest.mark.repeat.The implementation also:
[current-total]node ID suffixes, including parameterized IDs such as[param-1-10];function,class,module, andsessionrepeat ordering;pytest-xdist and filtering
The repeated items are created before
pytest_collection_finish, so xdist workers report the final unique node IDs to the controller and each repetition can be scheduled independently.For example:
pytest -n 4 -k important --count=10collects the original tests, applies
-k important, expands each selected test ten times, and then distributes those repeated items across workers.Because filtering now happens before repeat expansion,
-kand-mmatch the original test IDs and markers. Generated repeat suffixes such as[1-10]are not available as filtering targets. Final reports and xdist scheduling still use the suffixed node IDs.Performance characteristics
Collection hooks such as
pytest_itemcollectednow run only for the original items, and ordinarypytest_collection_modifyitemsimplementations process the unexpanded list. The final runner and xdist item list still containsselected item count × repeat countentries, so execution scheduling and final item storage remain proportional to the number of repetitions.Tests
Added coverage for:
-kdeselection;--collect-onlytotals;The existing parameterization, repeat marker, step number, unittest, and repeat-scope tests continue to pass.
Locally verified with: