summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-03-04 19:37:25 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-03-04 19:37:25 -0500
commit4ce893437c9e777216cac981c5909572fa10d9df (patch)
tree0672d2aaec261a3e9da3c5596f7a578f3b7605b2
parent00095fcbbfd00f0b1d1a9e519a88c8e57898a3aa (diff)
downloadpython-coveragepy-git-4ce893437c9e777216cac981c5909572fa10d9df.tar.gz
refactor: replace unittest_mixins.EnvironmentAwareMixin with a pytest adapter
-rw-r--r--tests/coveragetest.py4
-rw-r--r--tests/mixins.py18
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)