Commit e94518d
committed
config: use one
Previously, `Parser` would create a new `ArgumentParser` for each
parsing call (of which there are several during pytest initialization).
Besides being a bit wasteful, it makes things hard to follow, especially
since one `ArgumentParser` was saved on the `Parser` (in `optparser`).
It makes a few refactorings I am planning difficult to pull off.
So now, `Parser` instantiates one `ArgumentParser` in `__init__` and
just adds groups/arguments to it immediately. There's more
synchronization needed, but since arguments can only be added, never
removed, it's not bad.
One gotcha, in order to control `--help` group orders we must access
argparse internals since it doesn't provide a way to do it. I checked
and the relevant code hasn't changed since argparse was introduced 15
years ago. So hopefully it will continue to be fine.ArgumentParser instead of creating new one for each parse1 parent bda322a commit e94518d
File tree
4 files changed
+53
-52
lines changed- src/_pytest/config
- testing
4 files changed
+53
-52
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1157 | 1157 | | |
1158 | 1158 | | |
1159 | 1159 | | |
1160 | | - | |
| 1160 | + | |
1161 | 1161 | | |
1162 | 1162 | | |
1163 | 1163 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | 39 | | |
42 | 40 | | |
43 | 41 | | |
| |||
46 | 44 | | |
47 | 45 | | |
48 | 46 | | |
49 | | - | |
50 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
51 | 50 | | |
52 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
53 | 61 | | |
54 | 62 | | |
55 | 63 | | |
56 | | - | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
57 | 72 | | |
58 | 73 | | |
59 | 74 | | |
| |||
78 | 93 | | |
79 | 94 | | |
80 | 95 | | |
81 | | - | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
82 | 99 | | |
83 | 100 | | |
84 | 101 | | |
85 | 102 | | |
86 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
87 | 107 | | |
88 | 108 | | |
89 | 109 | | |
| |||
102 | 122 | | |
103 | 123 | | |
104 | 124 | | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | 125 | | |
125 | 126 | | |
126 | 127 | | |
| |||
135 | 136 | | |
136 | 137 | | |
137 | 138 | | |
138 | | - | |
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | 166 | | |
168 | 167 | | |
169 | 168 | | |
| |||
175 | 174 | | |
176 | 175 | | |
177 | 176 | | |
178 | | - | |
| 177 | + | |
179 | 178 | | |
180 | 179 | | |
181 | 180 | | |
| |||
392 | 391 | | |
393 | 392 | | |
394 | 393 | | |
| 394 | + | |
395 | 395 | | |
396 | | - | |
397 | | - | |
398 | | - | |
| 396 | + | |
399 | 397 | | |
400 | 398 | | |
401 | 399 | | |
| 400 | + | |
402 | 401 | | |
403 | | - | |
404 | 402 | | |
405 | 403 | | |
406 | 404 | | |
| |||
435 | 433 | | |
436 | 434 | | |
437 | 435 | | |
| 436 | + | |
438 | 437 | | |
439 | 438 | | |
| 439 | + | |
| 440 | + | |
440 | 441 | | |
441 | 442 | | |
442 | 443 | | |
443 | 444 | | |
444 | 445 | | |
445 | 446 | | |
446 | 447 | | |
447 | | - | |
448 | | - | |
| 448 | + | |
| 449 | + | |
449 | 450 | | |
450 | 451 | | |
451 | 452 | | |
452 | | - | |
453 | | - | |
| 453 | + | |
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
459 | 459 | | |
460 | 460 | | |
461 | | - | |
| 461 | + | |
462 | 462 | | |
463 | 463 | | |
464 | 464 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2304 | 2304 | | |
2305 | 2305 | | |
2306 | 2306 | | |
2307 | | - | |
2308 | 2307 | | |
2309 | 2308 | | |
2310 | | - | |
| 2309 | + | |
2311 | 2310 | | |
2312 | 2311 | | |
2313 | 2312 | | |
| |||
2410 | 2409 | | |
2411 | 2410 | | |
2412 | 2411 | | |
2413 | | - | |
2414 | | - | |
| 2412 | + | |
2415 | 2413 | | |
2416 | 2414 | | |
2417 | 2415 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
| |||
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
74 | | - | |
| 75 | + | |
75 | 76 | | |
76 | | - | |
77 | 77 | | |
78 | 78 | | |
79 | | - | |
| 79 | + | |
80 | 80 | | |
81 | | - | |
82 | 81 | | |
83 | 82 | | |
84 | 83 | | |
| |||
88 | 87 | | |
89 | 88 | | |
90 | 89 | | |
91 | | - | |
| 90 | + | |
92 | 91 | | |
93 | 92 | | |
94 | | - | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
95 | 96 | | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
101 | 104 | | |
102 | 105 | | |
103 | 106 | | |
| |||
0 commit comments