Move selection before repeat - #99
Conversation
|
Hi @okken Can you take a look? I feel this is important for large-scale testing. So much appreciate for your time :) |
|
applying the pytest ai policy here - thisis a massive structural change that can only be described as letting a statistic monkey play with fire |
|
@RonnyPfannschmidt Thanks for the feedback. I think it's worth discussing the underlying problem this PR is trying to solve rather than dismissing it just because of AI involvement. I think that's a meaningful improvement for this use case, and I'd prefer to discuss the design itself rather than whether the PR should be dismissed under the AI policy. If there are concerns with my proposed approach (selecting first and expanding afterward), I'd be happy to discuss those. From my perspective, expanding the entire workload before applying selection no longer makes sense for large-scale repeat workloads, and I'd like to better understand the reasons behind the current design. AI is a tool, and I understand it has been abused to spam every repo of open-source. If the insight of this PR is good enough, I don't bother to use it to make my idea possible. Of course I don't know much about B.R. |
|
we are currently at the pytest sprint and actively discussion reasonable solutions for this the reason i buried specifically this pr is that it does very problematic things around copying nodes and mutating them and had no prior technical discussion |
I agree. I am glad it draws discussions. Prior solutions to use pattern matching with pytest-repeat (#15 ) is reasonable but not so satisfying. |
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: