You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
main: add explicit handling of overlapping collection arguments
Consider a pytest invocation like `pytest tests/ tests/test_it.py`. What
should happen?
Currently what happens is that only `tests/test_it.py` is run, which is
obviously wrong. This regressed in the big package collection rework
(PR #11646).
The reason it regressed is the way pytest collection works. See #12083
for (some) details.
I have made an attempt to fix the problem directly in the collection
loop, but failed. The main challenge is the node caching, i.e. when
should a collector node be reused when it is needed for several
collection arguments. I believe it is possible to make it work, but it's
hard.
In order to not leave this embarrassing bug lingering for any longer,
this instead takes an easier approach, which is to massage the
collection argument list itself such that issues with overlapping nodes
don't come up during collection at all. This *adds* complexity instead
of simplifying things, but I hope it should be good enough in practice
for now, and maybe we can revisit in the future.
This change introduces behavioral changes, mainly:
- `pytest a/b a/` is equivalent to `pytest a`; if there is an `a/a` then
`a/b` will *not* be ordered before `a/a`. So the ability to order a
subset before a superset is lost.
- `pytest x.py x.py` does *not* run the file twice; previously we took
an explicit request like this to mean that it should.
The `--keep-duplicates` option remains as a sort of "expert mode" that
retains its current behavior; though it is still subtly broken in that
*collector nodes* are also duplicated (not just the items). A fix for
that requires the harder change.
Fix#12083.
Fixed a bug where an invocation such as `pytest a/ a/b` would cause only tests from `a/b` to run, and not other tests under `a/`.
2
+
3
+
The fix entails a few breaking changes to how such overlapping arguments and duplicates are handled:
4
+
5
+
1. `pytest a/b a/` or `pytest a/ a/b` are equivalent to `pytest a`; if an argument overlaps another arguments, only the prefix remains.
6
+
7
+
2. `pytest x.py x.py` is equivalent to `pytest x.py`; previously such an invocation was taken as an explicit request to run the tests from the file twice.
8
+
9
+
If you rely on these behaviors, consider using :ref:`--keep-duplicates <duplicate-paths>`, which retains its existing behavior (including the bug).
0 commit comments