Skip to content

Commit

Permalink
Add maxprocesses option to limit the maximum number of workers when u…
Browse files Browse the repository at this point in the history
…sing numprocesses=auto

Fix #337
  • Loading branch information
pristupa committed Oct 17, 2018
1 parent 86e2fb5 commit 5ce8a6e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/337.feature
@@ -0,0 +1,3 @@
```
Add --maxprocesses command-line option to limit the maximum number of workers when using --numprocesses=auto
```
4 changes: 4 additions & 0 deletions testing/test_plugin.py
Expand Up @@ -25,6 +25,10 @@ def test_dist_options(testdir):
check_options(config)
assert config.option.dist == "load"
assert config.option.tx == ["popen"] * 2
config = testdir.parseconfigure("--numprocesses", "3", "--maxprocesses", "2")
check_options(config)
assert config.option.dist == "load"
assert config.option.tx == ["popen"] * 2
config = testdir.parseconfigure("-d")
check_options(config)
assert config.option.dist == "load"
Expand Down
13 changes: 12 additions & 1 deletion xdist/plugin.py
Expand Up @@ -47,6 +47,14 @@ def pytest_addoption(parser):
"you can use 'auto' here for auto detection CPUs number on "
"host system",
)
group._addoption(
"--maxprocesses",
dest="maxprocesses",
metavar="maxprocesses",
action="store",
type=int,
help="limit the maximum number of workers to process the tests when using --numprocesses=auto",
)
group.addoption(
"--max-worker-restart",
"--max-slave-restart",
Expand Down Expand Up @@ -172,7 +180,10 @@ def pytest_cmdline_main(config):
if config.option.numprocesses:
if config.option.dist == "no":
config.option.dist = "load"
config.option.tx = ["popen"] * config.option.numprocesses
numprocesses = config.option.numprocesses
if config.option.maxprocesses:
numprocesses = min(numprocesses, config.option.maxprocesses)
config.option.tx = ["popen"] * numprocesses
if config.option.distload:
config.option.dist = "load"
val = config.getvalue
Expand Down
1 change: 1 addition & 0 deletions xdist/remote.py
Expand Up @@ -234,6 +234,7 @@ def remote_initconfig(option_dict, args):
config.option.dist = "no"
config.option.distload = False
config.option.numprocesses = None
config.option.maxprocesses = None
config.args = args
return config

Expand Down

0 comments on commit 5ce8a6e

Please sign in to comment.