refactor cpu number autodetection to avoid the regression
This commit is contained in:
@@ -1,3 +1,9 @@
|
|||||||
|
1.13.1
|
||||||
|
-------
|
||||||
|
|
||||||
|
- fix a regression -n 0 now disables xdist again
|
||||||
|
|
||||||
|
|
||||||
1.13
|
1.13
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
@@ -16,7 +22,7 @@
|
|||||||
- new "--max-slave-restart" option that can be used to control maximum
|
- new "--max-slave-restart" option that can be used to control maximum
|
||||||
number of times pytest-xdist can restart slaves due to crashes. Thanks to
|
number of times pytest-xdist can restart slaves due to crashes. Thanks to
|
||||||
Anatoly Bubenkov for the report and Bruno Oliveira for the PR.
|
Anatoly Bubenkov for the report and Bruno Oliveira for the PR.
|
||||||
|
|
||||||
- release as wheel
|
- release as wheel
|
||||||
|
|
||||||
- "-n" option now can be set to "auto" for automatic detection of number
|
- "-n" option now can be set to "auto" for automatic detection of number
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
import multiprocessing
|
|
||||||
|
|
||||||
import py
|
import py
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
|
||||||
|
def parse_numprocesses(s):
|
||||||
|
if s == 'auto':
|
||||||
|
import multiprocessing
|
||||||
|
return multiprocessing.cpu_count()
|
||||||
|
else:
|
||||||
|
return int(s)
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
def pytest_addoption(parser):
|
||||||
group = parser.getgroup("xdist", "distributed and subprocess testing")
|
group = parser.getgroup("xdist", "distributed and subprocess testing")
|
||||||
group._addoption('-n', dest="numprocesses", metavar="numprocesses",
|
group._addoption('-n', dest="numprocesses", metavar="numprocesses",
|
||||||
action="store",
|
action="store",
|
||||||
|
type=parse_numprocesses,
|
||||||
help="shortcut for '--dist=load --tx=NUM*popen', "
|
help="shortcut for '--dist=load --tx=NUM*popen', "
|
||||||
"you can use 'auto' here for auto detection CPUs number on "
|
"you can use 'auto' here for auto detection CPUs number on "
|
||||||
"host system")
|
"host system")
|
||||||
@@ -68,13 +76,6 @@ def pytest_configure(config):
|
|||||||
@pytest.mark.tryfirst
|
@pytest.mark.tryfirst
|
||||||
def pytest_cmdline_main(config):
|
def pytest_cmdline_main(config):
|
||||||
if config.option.numprocesses:
|
if config.option.numprocesses:
|
||||||
if config.option.numprocesses == 'auto':
|
|
||||||
config.option.numprocesses = multiprocessing.cpu_count()
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
config.option.numprocesses = int(config.option.numprocesses)
|
|
||||||
except ValueError:
|
|
||||||
config.option.numprocesses = 1
|
|
||||||
config.option.dist = "load"
|
config.option.dist = "load"
|
||||||
config.option.tx = ['popen'] * config.option.numprocesses
|
config.option.tx = ['popen'] * config.option.numprocesses
|
||||||
if config.option.distload:
|
if config.option.distload:
|
||||||
|
|||||||
Reference in New Issue
Block a user