@@ -27,10 +27,14 @@ def cpu_count():
27
27
return n if n else 1
28
28
29
29
30
+ class AutoInt (int ):
31
+ """Mark value as auto-detected."""
32
+
33
+
30
34
def parse_numprocesses (s ):
31
35
if s == "auto" :
32
- return auto_detect_cpus ()
33
- else :
36
+ return AutoInt ( auto_detect_cpus () )
37
+ elif s is not None :
34
38
return int (s )
35
39
36
40
@@ -45,7 +49,7 @@ def pytest_addoption(parser):
45
49
type = parse_numprocesses ,
46
50
help = "shortcut for '--dist=load --tx=NUM*popen', "
47
51
"you can use 'auto' here for auto detection CPUs number on "
48
- "host system" ,
52
+ "host system and it will be 0 when used with --pdb " ,
49
53
)
50
54
group .addoption (
51
55
"--maxprocesses" ,
@@ -177,6 +181,10 @@ def pytest_configure(config):
177
181
178
182
@pytest .mark .tryfirst
179
183
def pytest_cmdline_main (config ):
184
+ usepdb = config .getoption ("usepdb" ) # a core option
185
+ if isinstance (config .option .numprocesses , AutoInt ):
186
+ config .option .numprocesses = 0 if usepdb else int (config .option .numprocesses )
187
+
180
188
if config .option .numprocesses :
181
189
if config .option .dist == "no" :
182
190
config .option .dist = "load"
@@ -188,11 +196,10 @@ def pytest_cmdline_main(config):
188
196
config .option .dist = "load"
189
197
val = config .getvalue
190
198
if not val ("collectonly" ):
191
- usepdb = config .getoption ("usepdb" ) # a core option
192
199
if val ("dist" ) != "no" :
193
200
if usepdb :
194
201
raise pytest .UsageError (
195
- "--pdb is incompatible with distributing tests; try using -n0."
202
+ "--pdb is incompatible with distributing tests; try using -n0 or -nauto ."
196
203
) # noqa: E501
197
204
198
205
0 commit comments