File tree 3 files changed +30
-15
lines changed 3 files changed +30
-15
lines changed Original file line number Diff line number Diff line change
1
+ Workaround cpu detection on Travis CI
Original file line number Diff line number Diff line change @@ -45,6 +45,11 @@ def test_auto_detect_cpus(testdir, monkeypatch):
45
45
config = testdir .parseconfigure ("-nauto" )
46
46
assert config .getoption ('numprocesses' ) == 99
47
47
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
+
48
53
49
54
def test_boxed_with_collect_only (testdir ):
50
55
from xdist .plugin import pytest_cmdline_main as check_options
Original file line number Diff line number Diff line change
1
+ import os
2
+
1
3
import py
2
4
import pytest
3
5
4
6
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
7
14
try :
8
- from os import sched_getaffinity
15
+ from os import cpu_count
9
16
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 ))
17
21
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 ()
23
32
else :
24
33
return int (s )
25
34
You can’t perform that action at this time.
0 commit comments