Commit 6764439
committed
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.1 parent 1efe0db commit 6764439
File tree
7 files changed
+783
-40
lines changed- changelog
- doc/en/example
- src/_pytest
- testing
7 files changed
+783
-40
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
| |||
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | 87 | | |
98 | 88 | | |
99 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
784 | | - | |
785 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
786 | 787 | | |
787 | 788 | | |
| 789 | + | |
788 | 790 | | |
789 | 791 | | |
790 | 792 | | |
791 | | - | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
792 | 803 | | |
793 | 804 | | |
794 | 805 | | |
| |||
976 | 987 | | |
977 | 988 | | |
978 | 989 | | |
979 | | - | |
980 | 990 | | |
981 | | - | |
| 991 | + | |
982 | 992 | | |
983 | | - | |
984 | | - | |
985 | 993 | | |
986 | 994 | | |
987 | 995 | | |
| |||
1033 | 1041 | | |
1034 | 1042 | | |
1035 | 1043 | | |
| 1044 | + | |
1036 | 1045 | | |
1037 | 1046 | | |
1038 | 1047 | | |
1039 | 1048 | | |
1040 | 1049 | | |
| 1050 | + | |
1041 | 1051 | | |
1042 | 1052 | | |
1043 | 1053 | | |
| |||
1109 | 1119 | | |
1110 | 1120 | | |
1111 | 1121 | | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
| 1143 | + | |
| 1144 | + | |
| 1145 | + | |
| 1146 | + | |
| 1147 | + | |
| 1148 | + | |
| 1149 | + | |
| 1150 | + | |
| 1151 | + | |
| 1152 | + | |
| 1153 | + | |
| 1154 | + | |
| 1155 | + | |
| 1156 | + | |
| 1157 | + | |
| 1158 | + | |
| 1159 | + | |
| 1160 | + | |
| 1161 | + | |
| 1162 | + | |
| 1163 | + | |
| 1164 | + | |
| 1165 | + | |
| 1166 | + | |
1112 | 1167 | | |
| 1168 | + | |
| 1169 | + | |
| 1170 | + | |
| 1171 | + | |
| 1172 | + | |
| 1173 | + | |
| 1174 | + | |
| 1175 | + | |
0 commit comments