Skip to content

Commit b0caf3d

Browse files
authored
Merge pull request #13221 from The-Compiler/help-section
Fix help sections for CLI options
2 parents d68ad68 + 174333e commit b0caf3d

File tree

8 files changed

+99
-97
lines changed

8 files changed

+99
-97
lines changed

changelog/13221.doc.rst

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved grouping of CLI options in the ``--help`` output.

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

+70-69
Original file line numberDiff line numberDiff line change
@@ -54,59 +54,16 @@
5454

5555

5656
def pytest_addoption(parser: Parser) -> None:
57-
parser.addini(
58-
"norecursedirs",
59-
"Directory patterns to avoid for recursion",
60-
type="args",
61-
default=[
62-
"*.egg",
63-
".*",
64-
"_darcs",
65-
"build",
66-
"CVS",
67-
"dist",
68-
"node_modules",
69-
"venv",
70-
"{arch}",
71-
],
72-
)
73-
parser.addini(
74-
"testpaths",
75-
"Directories to search for tests when no files or directories are given on the "
76-
"command line",
77-
type="args",
78-
default=[],
79-
)
80-
parser.addini(
81-
"collect_imported_tests",
82-
"Whether to collect tests in imported modules outside `testpaths`",
83-
type="bool",
84-
default=True,
85-
)
8657
group = parser.getgroup("general", "Running and selection options")
87-
group._addoption(
58+
group._addoption( # private to use reserved lower-case short option
8859
"-x",
8960
"--exitfirst",
9061
action="store_const",
9162
dest="maxfail",
9263
const=1,
9364
help="Exit instantly on first error or failed test",
9465
)
95-
group = parser.getgroup("pytest-warnings")
9666
group.addoption(
97-
"-W",
98-
"--pythonwarnings",
99-
action="append",
100-
help="Set which warnings to report, see -W option of Python itself",
101-
)
102-
parser.addini(
103-
"filterwarnings",
104-
type="linelist",
105-
help="Each line specifies a pattern for "
106-
"warnings.filterwarnings. "
107-
"Processed after -W/--pythonwarnings.",
108-
)
109-
group._addoption(
11067
"--maxfail",
11168
metavar="num",
11269
action="store",
@@ -115,46 +72,37 @@ def pytest_addoption(parser: Parser) -> None:
11572
default=0,
11673
help="Exit after first num failures or errors",
11774
)
118-
group._addoption(
75+
group.addoption(
11976
"--strict-config",
12077
action="store_true",
12178
help="Any warnings encountered while parsing the `pytest` section of the "
12279
"configuration file raise errors",
12380
)
124-
group._addoption(
81+
group.addoption(
12582
"--strict-markers",
12683
action="store_true",
12784
help="Markers not registered in the `markers` section of the configuration "
12885
"file raise errors",
12986
)
130-
group._addoption(
87+
group.addoption(
13188
"--strict",
13289
action="store_true",
13390
help="(Deprecated) alias to --strict-markers",
13491
)
135-
group._addoption(
136-
"-c",
137-
"--config-file",
138-
metavar="FILE",
139-
type=str,
140-
dest="inifilename",
141-
help="Load configuration from `FILE` instead of trying to locate one of the "
142-
"implicit configuration files.",
143-
)
144-
group._addoption(
145-
"--continue-on-collection-errors",
146-
action="store_true",
147-
default=False,
148-
dest="continue_on_collection_errors",
149-
help="Force test execution even if collection errors occur",
92+
93+
group = parser.getgroup("pytest-warnings")
94+
group.addoption(
95+
"-W",
96+
"--pythonwarnings",
97+
action="append",
98+
help="Set which warnings to report, see -W option of Python itself",
15099
)
151-
group._addoption(
152-
"--rootdir",
153-
action="store",
154-
dest="rootdir",
155-
help="Define root directory for tests. Can be relative path: 'root_dir', './root_dir', "
156-
"'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: "
157-
"'$HOME/root_dir'.",
100+
parser.addini(
101+
"filterwarnings",
102+
type="linelist",
103+
help="Each line specifies a pattern for "
104+
"warnings.filterwarnings. "
105+
"Processed after -W/--pythonwarnings.",
158106
)
159107

160108
group = parser.getgroup("collect", "collection")
@@ -218,6 +166,13 @@ def pytest_addoption(parser: Parser) -> None:
218166
default=False,
219167
help="Don't ignore tests in a local virtualenv directory",
220168
)
169+
group.addoption(
170+
"--continue-on-collection-errors",
171+
action="store_true",
172+
default=False,
173+
dest="continue_on_collection_errors",
174+
help="Force test execution even if collection errors occur",
175+
)
221176
group.addoption(
222177
"--import-mode",
223178
default="prepend",
@@ -226,6 +181,35 @@ def pytest_addoption(parser: Parser) -> None:
226181
help="Prepend/append to sys.path when importing test modules and conftest "
227182
"files. Default: prepend.",
228183
)
184+
parser.addini(
185+
"norecursedirs",
186+
"Directory patterns to avoid for recursion",
187+
type="args",
188+
default=[
189+
"*.egg",
190+
".*",
191+
"_darcs",
192+
"build",
193+
"CVS",
194+
"dist",
195+
"node_modules",
196+
"venv",
197+
"{arch}",
198+
],
199+
)
200+
parser.addini(
201+
"testpaths",
202+
"Directories to search for tests when no files or directories are given on the "
203+
"command line",
204+
type="args",
205+
default=[],
206+
)
207+
parser.addini(
208+
"collect_imported_tests",
209+
"Whether to collect tests in imported modules outside `testpaths`",
210+
type="bool",
211+
default=True,
212+
)
229213
parser.addini(
230214
"consider_namespace_packages",
231215
type="bool",
@@ -234,6 +218,23 @@ def pytest_addoption(parser: Parser) -> None:
234218
)
235219

236220
group = parser.getgroup("debugconfig", "test session debugging and configuration")
221+
group._addoption( # private to use reserved lower-case short option
222+
"-c",
223+
"--config-file",
224+
metavar="FILE",
225+
type=str,
226+
dest="inifilename",
227+
help="Load configuration from `FILE` instead of trying to locate one of the "
228+
"implicit configuration files.",
229+
)
230+
group.addoption(
231+
"--rootdir",
232+
action="store",
233+
dest="rootdir",
234+
help="Define root directory for tests. Can be relative path: 'root_dir', './root_dir', "
235+
"'root_dir/another_dir/'; absolute path: '/home/user/root_dir'; path with variables: "
236+
"'$HOME/root_dir'.",
237+
)
237238
group.addoption(
238239
"--basetemp",
239240
dest="basetemp",

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",

0 commit comments

Comments
 (0)