Skip to content

Commit fe0d639

Browse files
authored
Merge pull request #854 from pv/test-env-type
Add test option to select which 'default' environment to use
2 parents 4f08a7f + 7b77736 commit fe0d639

File tree

8 files changed

+33
-15
lines changed

8 files changed

+33
-15
lines changed

.appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ build_script:
3636
- python setup.py build_ext -i
3737

3838
test_script:
39-
- python -m pytest -l --basetemp=%APPVEYOR_BUILD_FOLDER%\\tmp -n 2 -v -v --webdriver=FirefoxHeadless --timeout=1800 --durations=100 test
39+
- python -m pytest -l --basetemp=%APPVEYOR_BUILD_FOLDER%\\tmp -n 2 -v -v --environment-type=conda --webdriver=FirefoxHeadless --timeout=1800 --durations=100 test
4040

4141
after_build:
4242
# Clear up pip cache

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ install:
6565
export TRAVIS_PYTHON=`which python`
6666
export TRAVIS_PIP=`which pip`
6767
if [[ $USE_CONDA == true ]]; then
68+
ENVIRONMENT_TYPE=conda
6869
mkdir -p $HOME/download;
6970
export MINICONDA_SH="Miniconda3-latest-Linux-x86_64.sh";
7071
pushd $HOME/download;
@@ -78,6 +79,7 @@ install:
7879
conda info
7980
if $TRAVIS_PYTHON -c 'import virtualenv'; then echo "ERROR: virtualenv package is installed"; exit 1; fi;
8081
else
82+
ENVIRONMENT_TYPE=virtualenv
8183
if $TRAVIS_PYTHON -c 'import sys; sys.exit(0 if "__pypy__" in sys.modules else 1)'; then
8284
$TRAVIS_PIP install virtualenv;
8385
elif [[ "$TRAVIS_PYTHON_VERSION" == "3.8-dev" ]]; then
@@ -91,7 +93,7 @@ install:
9193
- $TRAVIS_PYTHON setup.py build_ext -i
9294

9395
script:
94-
- $TRAVIS_PYTHON -m pytest -l $COVERAGE -n 3 -v -v --webdriver=FirefoxHeadless --timeout=1800 --timeout-method=thread --durations=100 test
96+
- $TRAVIS_PYTHON -m pytest -l $COVERAGE -n 3 -v -v --environment-type=$ENVIRONMENT_TYPE --webdriver=FirefoxHeadless --timeout=1800 --timeout-method=thread --durations=100 test
9597

9698
after_script:
9799
- if [[ "$COVERAGE" != '' ]]; then

asv/environment.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def get_environment_class(conf, python):
434434
classes.insert(0, cls)
435435

436436
for cls in classes:
437-
if cls.matches(python):
437+
if cls.matches_python_fallback and cls.matches(python):
438438
return cls
439439
raise EnvironmentUnavailable(
440440
"No way to create environment for python='{0}'".format(python))
@@ -469,6 +469,7 @@ class Environment(object):
469469
project.
470470
"""
471471
tool_name = None
472+
matches_python_fallback = True
472473

473474
def __init__(self, conf, python, requirements, tagged_env_vars):
474475
"""

test/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import contextlib
3+
import pytest
34

45

56
def pytest_addoption(parser):
@@ -10,11 +11,23 @@ def pytest_addoption(parser):
1011
"with a return statement with selenium.webdriver object, for "
1112
"example 'return Chrome()'"))
1213

14+
parser.addoption("--environment-type", action="store", default=None,
15+
choices=("conda", "virtualenv"),
16+
help="environment_type to use in tests by default")
17+
1318

1419
def pytest_sessionstart(session):
1520
os.environ['PIP_NO_INDEX'] = '1'
1621
_monkeypatch_conda_lock(session.config)
1722

23+
# Unregister unwanted environment types
24+
env_type = session.config.getoption('environment_type')
25+
if env_type is not None:
26+
import asv.environment, asv.util
27+
28+
for cls in asv.util.iter_subclasses(asv.environment.Environment):
29+
cls.matches_python_fallback = (cls.tool_name in (env_type, "existing"))
30+
1831

1932
def _monkeypatch_conda_lock(config):
2033
import asv.plugins.conda

test/test_continuous.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,16 @@
1010
from asv.results import iter_results_for_machine
1111

1212
from . import tools
13-
from .tools import HAS_CONDA
14-
from .tools import dummy_packages
13+
from .tools import dummy_packages, get_default_environment_type
1514
from .test_workflow import basic_conf
1615

1716

1817
def test_continuous(capfd, basic_conf):
1918
tmpdir, local, conf, machine_file = basic_conf
2019

21-
if HAS_CONDA:
22-
env_spec = ("-E", "conda:{0[0]}.{0[1]}".format(sys.version_info))
23-
else:
24-
env_spec = ("-E", "virtualenv:{0[0]}.{0[1]}".format(sys.version_info))
20+
python = "{0[0]}.{0[1]}".format(sys.version_info)
21+
env_type = get_default_environment_type(conf, python)
22+
env_spec = ("-E", env_type + ":" + python)
2523

2624
# Check that asv continuous runs
2725
tools.run_asv_with_conf(conf, 'continuous', "master^", '--show-stderr',

test/test_run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from asv.commands.run import Run
2121

2222
from . import tools
23-
from .tools import dummy_packages, HAS_CONDA
23+
from .tools import dummy_packages
2424
from .test_workflow import basic_conf, generate_basic_conf
2525

2626

test/test_workflow.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from asv.util import check_output, which
2323

2424
from . import tools
25-
from .tools import dummy_packages, HAS_CONDA
25+
from .tools import dummy_packages, get_default_environment_type
2626

2727

2828
dummy_values = [
@@ -150,10 +150,9 @@ def test_run_publish(capfd, basic_conf):
150150
assert 'Running benchmarks.' not in text
151151

152152
# Check EXISTING and --environment work
153-
if HAS_CONDA:
154-
env_spec = ("-E", "conda:{0[0]}.{0[1]}".format(sys.version_info))
155-
else:
156-
env_spec = ("-E", "virtualenv:{0[0]}.{0[1]}".format(sys.version_info))
153+
python = "{0[0]}.{0[1]}".format(sys.version_info)
154+
env_type = get_default_environment_type(conf, python)
155+
env_spec = ("-E", env_type + ":" + python)
157156
tools.run_asv_with_conf(conf, 'run', "EXISTING", '--quick',
158157
'--bench=time_secondary.track_value',
159158
*env_spec,

test/tools.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from asv import util
3636
from asv import commands
3737
from asv import config
38+
from asv import environment
3839
from asv import runner
3940
from asv.commands.preview import create_httpd
4041
from asv.repo import get_repo
@@ -99,6 +100,10 @@
99100
from lockfile import LockFile
100101

101102

103+
def get_default_environment_type(conf, python):
104+
return environment.get_environment_class(conf, python).tool_name
105+
106+
102107
@contextmanager
103108
def locked_cache_dir(config, cache_key, timeout=900, tag=None):
104109
base_dir = config.cache.makedir(cache_key)

0 commit comments

Comments
 (0)