Skip to content

Commit 2861de3

Browse files
committed
Avoid using private _addoption
The only differences between the two is that: - `addoption` checks for conflicts, but `_addoption` does not - `addoption` complains if a lower-case short option is given, `_addoption` does not Yet it looks like using the latter has been inconsistently cargo-culted with newer options.
1 parent 71ae4d1 commit 2861de3

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

src/_pytest/capture.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@
4848

4949
def pytest_addoption(parser: Parser) -> None:
5050
group = parser.getgroup("general")
51-
group._addoption(
51+
group.addoption(
5252
"--capture",
5353
action="store",
5454
default="fd",
5555
metavar="method",
5656
choices=["fd", "sys", "no", "tee-sys"],
5757
help="Per-test capturing method: one of fd|sys|no|tee-sys",
5858
)
59-
group._addoption(
59+
group._addoption( # private to use reserved lower-case short option
6060
"-s",
6161
action="store_const",
6262
const="no",

src/_pytest/debugging.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,21 +40,21 @@ def _validate_usepdb_cls(value: str) -> tuple[str, str]:
4040

4141
def pytest_addoption(parser: Parser) -> None:
4242
group = parser.getgroup("general")
43-
group._addoption(
43+
group.addoption(
4444
"--pdb",
4545
dest="usepdb",
4646
action="store_true",
4747
help="Start the interactive Python debugger on errors or KeyboardInterrupt",
4848
)
49-
group._addoption(
49+
group.addoption(
5050
"--pdbcls",
5151
dest="usepdb_cls",
5252
metavar="modulename:classname",
5353
type=_validate_usepdb_cls,
5454
help="Specify a custom interactive Python debugger for use with --pdb."
5555
"For example: --pdbcls=IPython.terminal.debugger:TerminalPdb",
5656
)
57-
group._addoption(
57+
group.addoption(
5858
"--trace",
5959
dest="trace",
6060
action="store_true",

src/_pytest/helpconfig.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ def pytest_addoption(parser: Parser) -> None:
5555
help="Display pytest version and information about plugins. "
5656
"When given twice, also display information about plugins.",
5757
)
58-
group._addoption(
58+
group._addoption( # private to use reserved lower-case short option
5959
"-h",
6060
"--help",
6161
action=HelpAction,
6262
dest="help",
6363
help="Show help message and configuration info",
6464
)
65-
group._addoption(
65+
group._addoption( # private to use reserved lower-case short option
6666
"-p",
6767
action="append",
6868
dest="plugins",
@@ -90,7 +90,7 @@ def pytest_addoption(parser: Parser) -> None:
9090
"This file is opened with 'w' and truncated as a result, care advised. "
9191
"Default: pytestdebug.log.",
9292
)
93-
group._addoption(
93+
group._addoption( # private to use reserved lower-case short option
9494
"-o",
9595
"--override-ini",
9696
dest="override_ini",

src/_pytest/main.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@
5555

5656
def pytest_addoption(parser: Parser) -> None:
5757
group = parser.getgroup("general", "Running and selection options")
58-
group._addoption(
58+
group._addoption( # private to use reserved lower-case short option
5959
"-x",
6060
"--exitfirst",
6161
action="store_const",
6262
dest="maxfail",
6363
const=1,
6464
help="Exit instantly on first error or failed test",
6565
)
66-
group._addoption(
66+
group.addoption(
6767
"--maxfail",
6868
metavar="num",
6969
action="store",
@@ -72,19 +72,19 @@ def pytest_addoption(parser: Parser) -> None:
7272
default=0,
7373
help="Exit after first num failures or errors",
7474
)
75-
group._addoption(
75+
group.addoption(
7676
"--strict-config",
7777
action="store_true",
7878
help="Any warnings encountered while parsing the `pytest` section of the "
7979
"configuration file raise errors",
8080
)
81-
group._addoption(
81+
group.addoption(
8282
"--strict-markers",
8383
action="store_true",
8484
help="Markers not registered in the `markers` section of the configuration "
8585
"file raise errors",
8686
)
87-
group._addoption(
87+
group.addoption(
8888
"--strict",
8989
action="store_true",
9090
help="(Deprecated) alias to --strict-markers",
@@ -166,7 +166,7 @@ def pytest_addoption(parser: Parser) -> None:
166166
default=False,
167167
help="Don't ignore tests in a local virtualenv directory",
168168
)
169-
group._addoption(
169+
group.addoption(
170170
"--continue-on-collection-errors",
171171
action="store_true",
172172
default=False,
@@ -218,7 +218,7 @@ def pytest_addoption(parser: Parser) -> None:
218218
)
219219

220220
group = parser.getgroup("debugconfig", "test session debugging and configuration")
221-
group._addoption(
221+
group._addoption( # private to use reserved lower-case short option
222222
"-c",
223223
"--config-file",
224224
metavar="FILE",
@@ -227,7 +227,7 @@ def pytest_addoption(parser: Parser) -> None:
227227
help="Load configuration from `FILE` instead of trying to locate one of the "
228228
"implicit configuration files.",
229229
)
230-
group._addoption(
230+
group.addoption(
231231
"--rootdir",
232232
action="store",
233233
dest="rootdir",

src/_pytest/mark/__init__.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def test_eval(test_input, expected):
7979

8080
def pytest_addoption(parser: Parser) -> None:
8181
group = parser.getgroup("general")
82-
group._addoption(
82+
group._addoption( # private to use reserved lower-case short option
8383
"-k",
8484
action="store",
8585
dest="keyword",
@@ -99,7 +99,7 @@ def pytest_addoption(parser: Parser) -> None:
9999
"The matching is case-insensitive.",
100100
)
101101

102-
group._addoption(
102+
group._addoption( # private to use reserved lower-case short option
103103
"-m",
104104
action="store",
105105
dest="markexpr",

src/_pytest/pastebin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
def pytest_addoption(parser: Parser) -> None:
2222
group = parser.getgroup("terminal reporting")
23-
group._addoption(
23+
group.addoption(
2424
"--pastebin",
2525
metavar="mode",
2626
action="store",

src/_pytest/terminal.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -132,58 +132,58 @@ class TestShortLogReport(NamedTuple):
132132

133133
def pytest_addoption(parser: Parser) -> None:
134134
group = parser.getgroup("terminal reporting", "Reporting", after="general")
135-
group._addoption(
135+
group._addoption( # private to use reserved lower-case short option
136136
"-v",
137137
"--verbose",
138138
action="count",
139139
default=0,
140140
dest="verbose",
141141
help="Increase verbosity",
142142
)
143-
group._addoption(
143+
group.addoption(
144144
"--no-header",
145145
action="store_true",
146146
default=False,
147147
dest="no_header",
148148
help="Disable header",
149149
)
150-
group._addoption(
150+
group.addoption(
151151
"--no-summary",
152152
action="store_true",
153153
default=False,
154154
dest="no_summary",
155155
help="Disable summary",
156156
)
157-
group._addoption(
157+
group.addoption(
158158
"--no-fold-skipped",
159159
action="store_false",
160160
dest="fold_skipped",
161161
default=True,
162162
help="Do not fold skipped tests in short summary.",
163163
)
164-
group._addoption(
164+
group.addoption(
165165
"--force-short-summary",
166166
action="store_true",
167167
dest="force_short_summary",
168168
default=False,
169169
help="Force condensed summary output regardless of verbosity level.",
170170
)
171-
group._addoption(
171+
group._addoption( # private to use reserved lower-case short option
172172
"-q",
173173
"--quiet",
174174
action=MoreQuietAction,
175175
default=0,
176176
dest="verbose",
177177
help="Decrease verbosity",
178178
)
179-
group._addoption(
179+
group.addoption(
180180
"--verbosity",
181181
dest="verbose",
182182
type=int,
183183
default=0,
184184
help="Set verbosity. Default: 0.",
185185
)
186-
group._addoption(
186+
group._addoption( # private to use reserved lower-case short option
187187
"-r",
188188
action="store",
189189
dest="reportchars",
@@ -195,29 +195,29 @@ def pytest_addoption(parser: Parser) -> None:
195195
"(w)arnings are enabled by default (see --disable-warnings), "
196196
"'N' can be used to reset the list. (default: 'fE').",
197197
)
198-
group._addoption(
198+
group.addoption(
199199
"--disable-warnings",
200200
"--disable-pytest-warnings",
201201
default=False,
202202
dest="disable_warnings",
203203
action="store_true",
204204
help="Disable warnings summary",
205205
)
206-
group._addoption(
206+
group._addoption( # private to use reserved lower-case short option
207207
"-l",
208208
"--showlocals",
209209
action="store_true",
210210
dest="showlocals",
211211
default=False,
212212
help="Show locals in tracebacks (disabled by default)",
213213
)
214-
group._addoption(
214+
group.addoption(
215215
"--no-showlocals",
216216
action="store_false",
217217
dest="showlocals",
218218
help="Hide locals in tracebacks (negate --showlocals passed through addopts)",
219219
)
220-
group._addoption(
220+
group.addoption(
221221
"--tb",
222222
metavar="style",
223223
action="store",
@@ -226,14 +226,14 @@ def pytest_addoption(parser: Parser) -> None:
226226
choices=["auto", "long", "short", "no", "line", "native"],
227227
help="Traceback print mode (auto/long/short/line/native/no)",
228228
)
229-
group._addoption(
229+
group.addoption(
230230
"--xfail-tb",
231231
action="store_true",
232232
dest="xfail_tb",
233233
default=False,
234234
help="Show tracebacks for xfail (as long as --tb != no)",
235235
)
236-
group._addoption(
236+
group.addoption(
237237
"--show-capture",
238238
action="store",
239239
dest="showcapture",
@@ -242,14 +242,14 @@ def pytest_addoption(parser: Parser) -> None:
242242
help="Controls how captured stdout/stderr/log is shown on failed tests. "
243243
"Default: all.",
244244
)
245-
group._addoption(
245+
group.addoption(
246246
"--fulltrace",
247247
"--full-trace",
248248
action="store_true",
249249
default=False,
250250
help="Don't cut any tracebacks (default is to cut)",
251251
)
252-
group._addoption(
252+
group.addoption(
253253
"--color",
254254
metavar="color",
255255
action="store",
@@ -258,7 +258,7 @@ def pytest_addoption(parser: Parser) -> None:
258258
choices=["yes", "no", "auto"],
259259
help="Color terminal output (yes/no/auto)",
260260
)
261-
group._addoption(
261+
group.addoption(
262262
"--code-highlight",
263263
default="yes",
264264
choices=["yes", "no"],

0 commit comments

Comments
 (0)