Skip to content

Commit 368f6c6

Browse files
committed
Fix '-n logical' inconsistencies and review --help formatting
Fix pytest-dev#1021 and review formatting of the --help messages, following pytest's rules for consistency.
1 parent ce9b01e commit 368f6c6

File tree

3 files changed

+36
-32
lines changed

3 files changed

+36
-32
lines changed

docs/distribution.rst

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 31 additions & 27 deletions
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,25 @@ 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, falls back to 1.\n"
79+
"Forced to 0 (disabled) when used with --pdb.",
7680
)
7781
group.addoption(
7882
"--maxprocesses",
7983
dest="maxprocesses",
8084
metavar="maxprocesses",
8185
action="store",
8286
type=int,
83-
help="limit the maximum number of workers to process the tests when using --numprocesses=auto",
87+
help="Limit the maximum number of workers to process the tests when using --numprocesses with 'auto' or 'logical'",
8488
)
8589
group.addoption(
8690
"--max-worker-restart",
8791
action="store",
8892
default=None,
8993
dest="maxworkerrestart",
90-
help="maximum number of workers that can be restarted "
94+
help="Maximum number of workers that can be restarted "
9195
"when crashed (set to zero to disable this feature)",
9296
)
9397
group.addoption(
@@ -106,18 +110,18 @@ def pytest_addoption(parser):
106110
dest="dist",
107111
default="no",
108112
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"
113+
"Set mode for distributing tests to exec environments.\n\n"
114+
"each: Send each test to all available environments.\n\n"
115+
"load: Load balance by sending any pending test to any"
112116
" available environment.\n\n"
113-
"loadscope: load balance by sending pending groups of tests in"
117+
"loadscope: Load balance by sending pending groups of tests in"
114118
" the same scope to any available environment.\n\n"
115-
"loadfile: load balance by sending test grouped by file"
119+
"loadfile: Load balance by sending test grouped by file"
116120
" 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."
121+
"loadgroup: Like 'load', but sends tests marked with 'xdist_group' to the same worker.\n\n"
122+
"worksteal: Split the test suite between available environments,"
123+
" then re-balance when any worker runs out of tests.\n\n"
124+
"(default) no: Run tests inprocess, don't distribute."
121125
),
122126
)
123127
group.addoption(
@@ -127,8 +131,8 @@ def pytest_addoption(parser):
127131
default=[],
128132
metavar="xspec",
129133
help=(
130-
"add a test execution environment. some examples: "
131-
"--tx popen//python=python2.5 --tx socket=192.168.1.102:8888 "
134+
"Add a test execution environment. Some examples:\n"
135+
"--tx popen//python=python2.5 --tx socket=192.168.1.102:8888\n"
132136
"--tx [email protected]//chdir=testcache"
133137
),
134138
)
@@ -137,29 +141,29 @@ def pytest_addoption(parser):
137141
action="store_true",
138142
dest="distload",
139143
default=False,
140-
help="load-balance tests. shortcut for '--dist=load'",
144+
help="Load-balance tests. Shortcut for '--dist=load'.",
141145
)
142146
group.addoption(
143147
"--rsyncdir",
144148
action="append",
145149
default=[],
146150
metavar="DIR",
147-
help="add directory for rsyncing to remote tx nodes.",
151+
help="Add directory for rsyncing to remote tx nodes",
148152
)
149153
group.addoption(
150154
"--rsyncignore",
151155
action="append",
152156
default=[],
153157
metavar="GLOB",
154-
help="add expression for ignores when rsyncing to remote tx nodes.",
158+
help="Add expression for ignores when rsyncing to remote tx nodes",
155159
)
156160
group.addoption(
157161
"--testrunuid",
158162
action="store",
159163
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 "
164+
"Provide an identifier shared amongst all workers as the value of "
165+
"the 'testrun_uid' fixture.\n"
166+
"If not provided, 'testrun_uid' is filled with a new unique string "
163167
"on every test run."
164168
),
165169
)
@@ -168,13 +172,13 @@ def pytest_addoption(parser):
168172
action="store",
169173
type=int,
170174
help=(
171-
"Maximum number of tests scheduled in one step for --dist=load. "
175+
"Maximum number of tests scheduled in one step for --dist=load.\n"
172176
"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. "
177+
"one - might be useful for a small number of slow tests.\n"
174178
"Larger numbers will allow the scheduler to submit consecutive "
175-
"chunks of tests to workers - allows reusing fixtures. "
179+
"chunks of tests to workers - allows reusing fixtures.\n"
176180
"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. "
181+
"worker at the start. Only later tests can be scheduled one by one.\n"
178182
"Unlimited if not set."
179183
),
180184
)

0 commit comments

Comments
 (0)