From a82a5e7abe960708fece0a79f0ea1ca702ee2d31 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Thu, 14 May 2020 17:09:33 +0800 Subject: [PATCH] Add pytest option to globally switch resolver --- .travis.yml | 4 ++-- tests/conftest.py | 32 ++++++++++++++++++++++++++++---- tools/travis/run.sh | 12 ++++++++++-- tox.ini | 1 - 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index b44b07b1e..02c71a243 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,10 +57,10 @@ jobs: - stage: experimental env: - GROUP=1 - - PIP_UNSTABLE_FEATURE=resolver + - NEW_RESOLVER=1 - env: - GROUP=2 - - PIP_UNSTABLE_FEATURE=resolver + - NEW_RESOLVER=1 fast_finish: true allow_failures: diff --git a/tests/conftest.py b/tests/conftest.py index faec4f641..bf8cd7975 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,11 +30,23 @@ if MYPY_CHECK_RUNNING: def pytest_addoption(parser): parser.addoption( - "--keep-tmpdir", action="store_true", - default=False, help="keep temporary test directories" + "--keep-tmpdir", + action="store_true", + default=False, + help="keep temporary test directories", + ) + parser.addoption( + "--new-resolver", + action="store_true", + default=False, + help="use new resolver in tests", + ) + parser.addoption( + "--use-venv", + action="store_true", + default=False, + help="use venv for virtual environment creation", ) - parser.addoption("--use-venv", action="store_true", - help="use venv for virtual environment creation") def pytest_collection_modifyitems(config, items): @@ -75,6 +87,18 @@ def pytest_collection_modifyitems(config, items): ) +@pytest.fixture(scope="session", autouse=True) +def use_new_resolver(request): + """Set environment variable to make pip default to the new resolver. + """ + new_resolver = request.config.getoption("--new-resolver") + if new_resolver: + os.environ["PIP_UNSTABLE_FEATURE"] = "resolver" + else: + os.environ.pop("PIP_UNSTABLE_FEATURE", None) + yield new_resolver + + @pytest.fixture(scope='session') def tmpdir_factory(request, tmpdir_factory): """ Modified `tmpdir_factory` session fixture diff --git a/tools/travis/run.sh b/tools/travis/run.sh index 86f975f4f..90e7d5708 100755 --- a/tools/travis/run.sh +++ b/tools/travis/run.sh @@ -37,16 +37,24 @@ if [[ -z "$TOXENV" ]]; then fi echo "TOXENV=${TOXENV}" +if [[ -z "$NEW_RESOLVER" ]]; then + RESOLVER_SWITCH='' +else + RESOLVER_SWITCH='--new-resolver' +fi + # Print the commands run for this test. set -x if [[ "$GROUP" == "1" ]]; then # Unit tests tox -- --use-venv -m unit -n auto # Integration tests (not the ones for 'pip install') - tox -- --use-venv -m integration -n auto --duration=5 -k "not test_install" + tox -- -m integration -n auto --duration=5 -k "not test_install" \ + --use-venv $RESOLVER_SWITCH elif [[ "$GROUP" == "2" ]]; then # Separate Job for running integration tests for 'pip install' - tox -- --use-venv -m integration -n auto --duration=5 -k "test_install" + tox -- -m integration -n auto --duration=5 -k "test_install" \ + --use-venv $RESOLVER_SWITCH else # Non-Testing Jobs should run once tox diff --git a/tox.ini b/tox.ini index f6d5cb741..f05473d97 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,6 @@ passenv = HTTP_PROXY HTTPS_PROXY NO_PROXY - PIP_UNSTABLE_FEATURE setenv = # This is required in order to get UTF-8 output inside of the subprocesses # that our tests use.