Merge pull request #317 from skirpichev/pypy3-numprocesses
Workaround cpu detection on Travis CI
This commit is contained in:
1
changelog/316.bugfix
Normal file
1
changelog/316.bugfix
Normal file
@@ -0,0 +1 @@
|
||||
Workaround cpu detection on Travis CI
|
||||
@@ -45,6 +45,11 @@ def test_auto_detect_cpus(testdir, monkeypatch):
|
||||
config = testdir.parseconfigure("-nauto")
|
||||
assert config.getoption('numprocesses') == 99
|
||||
|
||||
monkeypatch.delattr(os, 'sched_getaffinity', raising=False)
|
||||
monkeypatch.setenv('TRAVIS', 'true')
|
||||
config = testdir.parseconfigure("-nauto")
|
||||
assert config.getoption('numprocesses') == 2
|
||||
|
||||
|
||||
def test_boxed_with_collect_only(testdir):
|
||||
from xdist.plugin import pytest_cmdline_main as check_options
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
import os
|
||||
|
||||
import py
|
||||
import pytest
|
||||
|
||||
|
||||
def auto_detect_cpus():
|
||||
try:
|
||||
from os import sched_getaffinity
|
||||
except ImportError:
|
||||
if os.environ.get('TRAVIS') == 'true':
|
||||
# workaround https://bitbucket.org/pypy/pypy/issues/2375
|
||||
return 2
|
||||
try:
|
||||
from os import cpu_count
|
||||
except ImportError:
|
||||
from multiprocessing import cpu_count
|
||||
else:
|
||||
def cpu_count():
|
||||
return len(sched_getaffinity(0))
|
||||
|
||||
try:
|
||||
n = cpu_count()
|
||||
except NotImplementedError:
|
||||
return 1
|
||||
return n if n else 1
|
||||
|
||||
|
||||
def parse_numprocesses(s):
|
||||
if s == 'auto':
|
||||
try:
|
||||
from os import sched_getaffinity
|
||||
except ImportError:
|
||||
try:
|
||||
from os import cpu_count
|
||||
except ImportError:
|
||||
from multiprocessing import cpu_count
|
||||
else:
|
||||
def cpu_count():
|
||||
return len(sched_getaffinity(0))
|
||||
|
||||
try:
|
||||
n = cpu_count()
|
||||
except NotImplementedError:
|
||||
return 1
|
||||
return n if n else 1
|
||||
return auto_detect_cpus()
|
||||
else:
|
||||
return int(s)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user