Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f57c658

Browse files
authoredFeb 25, 2024··
Fix '-n logical' inconsistencies and review --help formatting (#1022)
Fix #1021 and review formatting of the --help messages, following pytest's rules for consistency.
1 parent ce9b01e commit f57c658

File tree

3 files changed

+38
-32
lines changed

3 files changed

+38
-32
lines changed
 

‎docs/distribution.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ This can lead to considerable speed ups, especially if your test suite takes a
1111
noticeable amount of time.
1212

1313
With ``-n auto``, pytest-xdist will use as many processes as your computer
14-
has CPU cores.
14+
has physical CPU cores.
1515

1616
Use ``-n logical`` to use the number of *logical* CPU cores rather than
17-
physical ones. This currently requires the ``psutil`` package to be installed;
18-
if it is not, pytest-xdist will fall back to ``-n auto`` behavior.
17+
physical ones. This currently requires the `psutil <https://pypi.org/project/psutil/>`__ package to be installed;
18+
if it is not or if it fails to determine the number of logical CPUs, fall back to ``-n auto`` behavior.
1919

2020
Pass a number, e.g. ``-n 8``, to specify the number of processes explicitly.
2121

‎src/xdist/looponfail.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ def pytest_addoption(parser):
2929
action="store_true",
3030
dest="looponfail",
3131
default=False,
32-
help="run tests in subprocess, wait for modified files "
33-
"and re-run failing test set until all pass.",
32+
help="Run tests in subprocess: wait for files to be modified, then "
33+
"re-run failing test set until all pass.",
3434
)
3535

3636

‎src/xdist/plugin.py

+33-27
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ def parse_numprocesses(s):
6161

6262
@pytest.hookimpl
6363
def pytest_addoption(parser):
64+
# 'Help' formatting (same rules as pytest's):
65+
# Start with capitalized letters.
66+
# If a single phrase, do not end with period. If more than one phrase, all phrases end with periods.
67+
# Use \n to separate logical lines.
6468
group = parser.getgroup("xdist", "distributed and subprocess testing")
6569
group._addoption(
6670
"-n",
@@ -69,25 +73,27 @@ def pytest_addoption(parser):
6973
metavar="numprocesses",
7074
action="store",
7175
type=parse_numprocesses,
72-
help="Shortcut for '--dist=load --tx=NUM*popen'. With 'auto', attempt "
73-
"to detect physical CPU count. With 'logical', detect logical CPU "
74-
"count. If physical CPU count cannot be found, falls back to logical "
75-
"count. This will be 0 when used with --pdb.",
76+
help="Shortcut for '--dist=load --tx=NUM*popen'.\n"
77+
"With 'logical', attempt to detect logical CPU count (requires psutil, falls back to 'auto').\n"
78+
"With 'auto', attempt to detect physical CPU count. If physical CPU count cannot be determined, "
79+
"falls back to 1.\n"
80+
"Forced to 0 (disabled) when used with --pdb.",
7681
)
7782
group.addoption(
7883
"--maxprocesses",
7984
dest="maxprocesses",
8085
metavar="maxprocesses",
8186
action="store",
8287
type=int,
83-
help="limit the maximum number of workers to process the tests when using --numprocesses=auto",
88+
help="Limit the maximum number of workers to process the tests when using --numprocesses "
89+
"with 'auto' or 'logical'",
8490
)
8591
group.addoption(
8692
"--max-worker-restart",
8793
action="store",
8894
default=None,
8995
dest="maxworkerrestart",
90-
help="maximum number of workers that can be restarted "
96+
help="Maximum number of workers that can be restarted "
9197
"when crashed (set to zero to disable this feature)",
9298
)
9399
group.addoption(
@@ -106,18 +112,18 @@ def pytest_addoption(parser):
106112
dest="dist",
107113
default="no",
108114
help=(
109-
"set mode for distributing tests to exec environments.\n\n"
110-
"each: send each test to all available environments.\n\n"
111-
"load: load balance by sending any pending test to any"
115+
"Set mode for distributing tests to exec environments.\n\n"
116+
"each: Send each test to all available environments.\n\n"
117+
"load: Load balance by sending any pending test to any"
112118
" available environment.\n\n"
113-
"loadscope: load balance by sending pending groups of tests in"
119+
"loadscope: Load balance by sending pending groups of tests in"
114120
" the same scope to any available environment.\n\n"
115-
"loadfile: load balance by sending test grouped by file"
121+
"loadfile: Load balance by sending test grouped by file"
116122
" to any available environment.\n\n"
117-
"loadgroup: like load, but sends tests marked with 'xdist_group' to the same worker.\n\n"
118-
"worksteal: split the test suite between available environments,"
119-
" then rebalance when any worker runs out of tests.\n\n"
120-
"(default) no: run tests inprocess, don't distribute."
123+
"loadgroup: Like 'load', but sends tests marked with 'xdist_group' to the same worker.\n\n"
124+
"worksteal: Split the test suite between available environments,"
125+
" then re-balance when any worker runs out of tests.\n\n"
126+
"(default) no: Run tests inprocess, don't distribute."
121127
),
122128
)
123129
group.addoption(
@@ -127,8 +133,8 @@ def pytest_addoption(parser):
127133
default=[],
128134
metavar="xspec",
129135
help=(
130-
"add a test execution environment. some examples: "
131-
"--tx popen//python=python2.5 --tx socket=192.168.1.102:8888 "
136+
"Add a test execution environment. Some examples:\n"
137+
"--tx popen//python=python2.5 --tx socket=192.168.1.102:8888\n"
132138
"--tx ssh=user@codespeak.net//chdir=testcache"
133139
),
134140
)
@@ -137,29 +143,29 @@ def pytest_addoption(parser):
137143
action="store_true",
138144
dest="distload",
139145
default=False,
140-
help="load-balance tests. shortcut for '--dist=load'",
146+
help="Load-balance tests. Shortcut for '--dist=load'.",
141147
)
142148
group.addoption(
143149
"--rsyncdir",
144150
action="append",
145151
default=[],
146152
metavar="DIR",
147-
help="add directory for rsyncing to remote tx nodes.",
153+
help="Add directory for rsyncing to remote tx nodes",
148154
)
149155
group.addoption(
150156
"--rsyncignore",
151157
action="append",
152158
default=[],
153159
metavar="GLOB",
154-
help="add expression for ignores when rsyncing to remote tx nodes.",
160+
help="Add expression for ignores when rsyncing to remote tx nodes",
155161
)
156162
group.addoption(
157163
"--testrunuid",
158164
action="store",
159165
help=(
160-
"provide an identifier shared amongst all workers as the value of "
161-
"the 'testrun_uid' fixture,\n\n,"
162-
"if not provided, 'testrun_uid' is filled with a new unique string "
166+
"Provide an identifier shared amongst all workers as the value of "
167+
"the 'testrun_uid' fixture.\n"
168+
"If not provided, 'testrun_uid' is filled with a new unique string "
163169
"on every test run."
164170
),
165171
)
@@ -168,13 +174,13 @@ def pytest_addoption(parser):
168174
action="store",
169175
type=int,
170176
help=(
171-
"Maximum number of tests scheduled in one step for --dist=load. "
177+
"Maximum number of tests scheduled in one step for --dist=load.\n"
172178
"Setting it to 1 will force pytest to send tests to workers one by "
173-
"one - might be useful for a small number of slow tests. "
179+
"one - might be useful for a small number of slow tests.\n"
174180
"Larger numbers will allow the scheduler to submit consecutive "
175-
"chunks of tests to workers - allows reusing fixtures. "
181+
"chunks of tests to workers - allows reusing fixtures.\n"
176182
"Due to implementation reasons, at least 2 tests are scheduled per "
177-
"worker at the start. Only later tests can be scheduled one by one. "
183+
"worker at the start. Only later tests can be scheduled one by one.\n"
178184
"Unlimited if not set."
179185
),
180186
)

0 commit comments

Comments
 (0)
Please sign in to comment.