From 9d4afbdfeca03907eee39efa7235255a0e4b3551 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Sat, 11 Jul 2015 12:14:48 -0300 Subject: [PATCH] Add test, CHANGELOG and docs for auto-cpu detection PR --- CHANGELOG | 2 ++ README.txt | 3 ++- testing/acceptance_test.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index a340dfa..7cf76e7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,8 @@ ------------------------- - release as wheel +- "-n" option now can be set to "auto" for automatic detection of number + of cpus in the host system. Thanks Suloev Dmitry for the PR. 1.12 ------------------------- diff --git a/README.txt b/README.txt index 5c23cca..0dbbfee 100644 --- a/README.txt +++ b/README.txt @@ -59,7 +59,8 @@ To send tests to multiple CPUs, type:: py.test -n NUM Especially for longer running tests or tests requiring -a lot of IO this can lead to considerable speed ups. +a lot of IO this can lead to considerable speed ups. This option can +also be set to ``auto`` for automatic detection of the number of CPUs. Running tests in a Python subprocess diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index 134d63c..0d04929 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -363,6 +363,19 @@ def test_terminate_on_hangingnode(testdir): ]) +def test_auto_detect_cpus(testdir, monkeypatch): + import multiprocessing + monkeypatch.setattr(multiprocessing, 'cpu_count', lambda: 3) + testdir.makeconftest(""" + def pytest_unconfigure(config): + with open('cpus', 'w') as f: + f.write('cpus = %s' % config.option.numprocesses) + """) + testdir.inline_run('-n=auto') + cpus_file = testdir.tmpdir.join('cpus') + assert cpus_file.read() == 'cpus = 3' + + @pytest.mark.xfail(reason="works if run outside test suite", run=False) def test_session_hooks(testdir): testdir.makeconftest("""