Skip to content

Commit b814db4

Browse files
authored
Merge pull request #317 from skirpichev/pypy3-numprocesses
Workaround cpu detection on Travis CI
2 parents 46119eb + ee0754b commit b814db4

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

changelog/316.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Workaround cpu detection on Travis CI

testing/test_plugin.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ def test_auto_detect_cpus(testdir, monkeypatch):
4545
config = testdir.parseconfigure("-nauto")
4646
assert config.getoption('numprocesses') == 99
4747

48+
monkeypatch.delattr(os, 'sched_getaffinity', raising=False)
49+
monkeypatch.setenv('TRAVIS', 'true')
50+
config = testdir.parseconfigure("-nauto")
51+
assert config.getoption('numprocesses') == 2
52+
4853

4954
def test_boxed_with_collect_only(testdir):
5055
from xdist.plugin import pytest_cmdline_main as check_options

xdist/plugin.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
1+
import os
2+
13
import py
24
import pytest
35

46

5-
def parse_numprocesses(s):
6-
if s == 'auto':
7+
def auto_detect_cpus():
8+
try:
9+
from os import sched_getaffinity
10+
except ImportError:
11+
if os.environ.get('TRAVIS') == 'true':
12+
# workaround https://bitbucket.org/pypy/pypy/issues/2375
13+
return 2
714
try:
8-
from os import sched_getaffinity
15+
from os import cpu_count
916
except ImportError:
10-
try:
11-
from os import cpu_count
12-
except ImportError:
13-
from multiprocessing import cpu_count
14-
else:
15-
def cpu_count():
16-
return len(sched_getaffinity(0))
17+
from multiprocessing import cpu_count
18+
else:
19+
def cpu_count():
20+
return len(sched_getaffinity(0))
1721

18-
try:
19-
n = cpu_count()
20-
except NotImplementedError:
21-
return 1
22-
return n if n else 1
22+
try:
23+
n = cpu_count()
24+
except NotImplementedError:
25+
return 1
26+
return n if n else 1
27+
28+
29+
def parse_numprocesses(s):
30+
if s == 'auto':
31+
return auto_detect_cpus()
2332
else:
2433
return int(s)
2534

0 commit comments

Comments
 (0)