summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-10-14 20:03:57 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-10-14 20:03:57 -0400
commit4a5cf280fe8622a4ccd03c07cdd6adf3207df20f (patch)
tree513d76089b6af0bacfa282ab4418dd554e1f3b57
parentec9070f1387e9713236f3b8c47447df44447df23 (diff)
downloadpython-coveragepy-git-4a5cf280fe8622a4ccd03c07cdd6adf3207df20f.tar.gz
test: we don't need two sys.path restorers
-rw-r--r--tests/coveragetest.py4
-rw-r--r--tests/mixins.py13
-rw-r--r--tests/test_mixins.py4
3 files changed, 6 insertions, 15 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index aad71134..a4e0ee02 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -24,7 +24,7 @@ from coverage.misc import import_local_file
from tests.helpers import arcs_to_arcz_repr, arcz_to_arcs, assert_count_equal
from tests.helpers import nice_file, run_command
-from tests.mixins import PytestBase, StdStreamCapturingMixin, SysPathModulesMixin, TempDirMixin
+from tests.mixins import PytestBase, StdStreamCapturingMixin, RestoreModulesMixin, TempDirMixin
# Status returns for the command line.
@@ -36,7 +36,7 @@ TESTS_DIR = os.path.dirname(__file__)
class CoverageTest(
StdStreamCapturingMixin,
- SysPathModulesMixin,
+ RestoreModulesMixin,
TempDirMixin,
PytestBase,
):
diff --git a/tests/mixins.py b/tests/mixins.py
index 95b2145a..4a3347b2 100644
--- a/tests/mixins.py
+++ b/tests/mixins.py
@@ -82,17 +82,8 @@ class TempDirMixin:
return make_file(filename, text, bytes, newline)
-class SysPathModulesMixin:
- """Auto-restore sys.path and the imported modules at the end of each test."""
-
- @pytest.fixture(autouse=True)
- def _save_sys_path(self):
- """Restore sys.path at the end of each test."""
- old_syspath = sys.path[:]
- try:
- yield
- finally:
- sys.path = old_syspath
+class RestoreModulesMixin:
+ """Auto-restore the imported modules at the end of each test."""
@pytest.fixture(autouse=True)
def _module_saving(self):
diff --git a/tests/test_mixins.py b/tests/test_mixins.py
index 1483b1a2..5692c334 100644
--- a/tests/test_mixins.py
+++ b/tests/test_mixins.py
@@ -7,7 +7,7 @@ import pytest
from coverage.misc import import_local_file
-from tests.mixins import TempDirMixin, SysPathModulesMixin
+from tests.mixins import TempDirMixin, RestoreModulesMixin
class TempDirMixinTest(TempDirMixin):
@@ -59,7 +59,7 @@ class TempDirMixinTest(TempDirMixin):
assert data == b"\x99\x33\x66hello\0"
-class SysPathModulessMixinTest(TempDirMixin, SysPathModulesMixin):
+class RestoreModulessMixinTest(TempDirMixin, RestoreModulesMixin):
"""Tests of SysPathModulesMixin."""
@pytest.mark.parametrize("val", [17, 42])