Merge pull request #317 from skirpichev/pypy3-numprocesses

Workaround cpu detection on Travis CI
This commit is contained in:
Bruno Oliveira
2018-07-27 09:02:55 -03:00
committed by GitHub
3 changed files with 31 additions and 16 deletions

1
changelog/316.bugfix Normal file
View File

@@ -0,0 +1 @@
Workaround cpu detection on Travis CI

View File

@@ -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

View File

@@ -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)