diff options
-rw-r--r-- | tests/coveragetest.py | 4 | ||||
-rw-r--r-- | tests/mixins.py | 13 | ||||
-rw-r--r-- | tests/test_mixins.py | 4 |
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]) |