From 4ec1dcef1eff63870c83b38f71e787aeb5d1dc3f Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Sun, 26 Jul 2020 13:07:22 +0100 Subject: [PATCH] General fixes --- src/tox/config/source/ini/__init__.py | 2 +- src/tox/config/source/ini/convert.py | 1 + src/tox/execute/outcome.py | 0 src/tox/pytest.py | 13 ++++++- src/tox/tox_env/python/virtual_env/runner.py | 5 +-- tests/unit/pytest/test_init.py | 39 +++++++++----------- 6 files changed, 34 insertions(+), 26 deletions(-) delete mode 100644 src/tox/execute/outcome.py diff --git a/src/tox/config/source/ini/__init__.py b/src/tox/config/source/ini/__init__.py index e1cd135ad..9ec14e6f9 100644 --- a/src/tox/config/source/ini/__init__.py +++ b/src/tox/config/source/ini/__init__.py @@ -170,7 +170,7 @@ def _load_raw_from(self, as_name, conf, key): if self._section is None: raise KeyError(key) value = self._section[key] - collapsed_newlines = value.replace("\\\n", "") # collapse explicit line splits + collapsed_newlines = value.replace("\\\r", "").replace("\\\n", "") # collapse explicit line splits replace_executed = replace(collapsed_newlines, conf, as_name, self._section_loader) # do replacements factor_selected = filter_for_env(replace_executed, as_name) # select matching factors # extend factors diff --git a/src/tox/config/source/ini/convert.py b/src/tox/config/source/ini/convert.py index 7e0b002e2..e0c090f7d 100644 --- a/src/tox/config/source/ini/convert.py +++ b/src/tox/config/source/ini/convert.py @@ -13,6 +13,7 @@ def to_path(value): @staticmethod def to_list(value): splitter = "\n" if "\n" in value else "," + splitter = splitter.replace("\r", "") for token in value.split(splitter): value = token.strip() if value: diff --git a/src/tox/execute/outcome.py b/src/tox/execute/outcome.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/tox/pytest.py b/src/tox/pytest.py index 1665181de..d6f201b9f 100644 --- a/src/tox/pytest.py +++ b/src/tox/pytest.py @@ -1,6 +1,7 @@ import os import sys import textwrap +from contextlib import contextmanager from pathlib import Path from typing import Any, Callable, Dict, List, Optional, Sequence @@ -23,6 +24,7 @@ def ensure_logging_framework_not_altered(): LOGGER.handlers = before_handlers +@contextmanager def check_os_environ(): old = os.environ.copy() to_clean = {k: os.environ.pop(k, None) for k in {ENV_VAR_KEY, "TOX_WORK_DIR", "PYTHONPATH"}} @@ -51,7 +53,16 @@ def check_os_environ(): pytest.fail(msg) -check_os_environ_stable = pytest.fixture(autouse=True)(check_os_environ) +@pytest.fixture(autouse=True) +def check_os_environ_stable(monkeypatch): + with check_os_environ(): + yield + monkeypatch.undo() + + +@pytest.fixture(autouse=True) +def no_color(monkeypatch, check_os_environ_stable): + monkeypatch.setenv("NO_COLOR", "yes") @pytest.fixture(name="tox_project") diff --git a/src/tox/tox_env/python/virtual_env/runner.py b/src/tox/tox_env/python/virtual_env/runner.py index dc0741c46..86fc22544 100644 --- a/src/tox/tox_env/python/virtual_env/runner.py +++ b/src/tox/tox_env/python/virtual_env/runner.py @@ -78,9 +78,8 @@ def package_env_name_type(self): def install_package(self): package = self.package_env.perform_packaging() - self.install_python_packages( - package, no_deps=True, develop=self.conf["package"] is PackageType.dev, force_reinstall=True, - ) + develop = self.conf["package"] is PackageType.dev + self.install_python_packages(package, no_deps=True, develop=develop, force_reinstall=True) @impl diff --git a/tests/unit/pytest/test_init.py b/tests/unit/pytest/test_init.py index 0bd2cb6dc..8d260c761 100644 --- a/tests/unit/pytest/test_init.py +++ b/tests/unit/pytest/test_init.py @@ -19,24 +19,21 @@ def test_init_base(tox_project): def test_env_var(monkeypatch): - monkeypatch.setenv("MORE", "B") - monkeypatch.setenv("EXTRA", "1") - monkeypatch.setenv("PYTHONPATH", "yes") - gen = check_os_environ() - next(gen) - monkeypatch.setenv("MAGIC", "A") - monkeypatch.setenv("MORE", "D") - monkeypatch.delenv("EXTRA") - - from tox.pytest import pytest as tox_pytest - - exp = "test changed environ extra {'MAGIC': 'A'} miss {'EXTRA': '1'} diff {'MORE = B vs D'}" - - def fail(msg): - assert msg == exp - - monkeypatch.setattr(tox_pytest, "fail", fail) - try: - gen.send(None) - except StopIteration: - pass + with monkeypatch.context() as m: + m.setenv("MORE", "B") + m.setenv("EXTRA", "1") + m.setenv("PYTHONPATH", "yes") + + with check_os_environ(): + m.setenv("MAGIC", "A") + m.setenv("MORE", "D") + m.delenv("EXTRA") + + from tox.pytest import pytest as tox_pytest + + exp = "test changed environ extra {'MAGIC': 'A'} miss {'EXTRA': '1'} diff {'MORE = B vs D'}" + + def fail(msg): + assert msg == exp + + m.setattr(tox_pytest, "fail", fail)