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") config = testdir.parseconfigure("-nauto")
assert config.getoption('numprocesses') == 99 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): def test_boxed_with_collect_only(testdir):
from xdist.plugin import pytest_cmdline_main as check_options from xdist.plugin import pytest_cmdline_main as check_options

View File

@@ -1,12 +1,16 @@
import os
import py import py
import pytest import pytest
def parse_numprocesses(s): def auto_detect_cpus():
if s == 'auto':
try: try:
from os import sched_getaffinity from os import sched_getaffinity
except ImportError: except ImportError:
if os.environ.get('TRAVIS') == 'true':
# workaround https://bitbucket.org/pypy/pypy/issues/2375
return 2
try: try:
from os import cpu_count from os import cpu_count
except ImportError: except ImportError:
@@ -20,6 +24,11 @@ def parse_numprocesses(s):
except NotImplementedError: except NotImplementedError:
return 1 return 1
return n if n else 1 return n if n else 1
def parse_numprocesses(s):
if s == 'auto':
return auto_detect_cpus()
else: else:
return int(s) return int(s)