Skip to content

Commit

Permalink
test: we don't need two sys.path restorers
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Oct 15, 2021
1 parent ec9070f commit 4a5cf28
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 15 deletions.
4 changes: 2 additions & 2 deletions tests/coveragetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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.
Expand All @@ -36,7 +36,7 @@

class CoverageTest(
StdStreamCapturingMixin,
SysPathModulesMixin,
RestoreModulesMixin,
TempDirMixin,
PytestBase,
):
Expand Down
13 changes: 2 additions & 11 deletions tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,8 @@ def make_file(self, filename, text="", bytes=b"", newline=None):
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):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from coverage.misc import import_local_file

from tests.mixins import TempDirMixin, SysPathModulesMixin
from tests.mixins import TempDirMixin, RestoreModulesMixin


class TempDirMixinTest(TempDirMixin):
Expand Down Expand Up @@ -59,7 +59,7 @@ def test_make_bytes_file(self):
assert data == b"\x99\x33\x66hello\0"


class SysPathModulessMixinTest(TempDirMixin, SysPathModulesMixin):
class RestoreModulessMixinTest(TempDirMixin, RestoreModulesMixin):
"""Tests of SysPathModulesMixin."""

@pytest.mark.parametrize("val", [17, 42])
Expand Down

0 comments on commit 4a5cf28

Please sign in to comment.