diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/coveragetest.py | 4 | ||||
-rw-r--r-- | tests/mixins.py | 18 |
2 files changed, 20 insertions, 2 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py index 3363fa89..906886f2 100644 --- a/tests/coveragetest.py +++ b/tests/coveragetest.py @@ -16,7 +16,7 @@ import sys import unittest import pytest -from unittest_mixins import EnvironmentAwareMixin, TempDirMixin +from unittest_mixins import TempDirMixin import coverage from coverage import env @@ -25,7 +25,7 @@ from coverage.cmdline import CoverageScript from tests.helpers import arcs_to_arcz_repr, arcz_to_arcs, assert_count_equal from tests.helpers import run_command, SuperModuleCleaner -from tests.mixins import StdStreamCapturingMixin, StopEverythingMixin +from tests.mixins import EnvironmentAwareMixin, StdStreamCapturingMixin, StopEverythingMixin # Status returns for the command line. diff --git a/tests/mixins.py b/tests/mixins.py index 9d096d4d..5abaa759 100644 --- a/tests/mixins.py +++ b/tests/mixins.py @@ -16,6 +16,24 @@ import pytest from coverage.misc import StopEverything +class EnvironmentAwareMixin: + """ + Adapter from pytst monkeypatch fixture to our environment variable methods. + """ + @pytest.fixture(autouse=True) + def _monkeypatch(self, monkeypatch): + """Get the monkeypatch fixture for our methods to use.""" + self._envpatcher = monkeypatch + + def set_environ(self, name, value): + """Set an environment variable `name` to be `value`.""" + self._envpatcher.setenv(name, value) + + def del_environ(self, name): + """Delete an environment variable, unless we set it.""" + self._envpatcher.delenv(name) + + def convert_skip_exceptions(method): """A decorator for test methods to convert StopEverything to SkipTest.""" @functools.wraps(method) |