Skip to content

Commit

Permalink
test: properly reset a few globals between every test
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Nov 18, 2021
1 parent ad1fcae commit 26b680d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 17 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from coverage import env
from coverage.exceptions import _StopEverything
from coverage.files import set_relative_directory


# Pytest will rewrite assertions in test modules, but not elsewhere.
Expand Down Expand Up @@ -72,6 +73,22 @@ def reset_sys_path():
sys.path[:] = sys_path


@pytest.fixture(autouse=True)
def reset_environment():
"""Make sure a test setting an envvar doesn't leak into another test."""
old_environ = os.environ.copy()
yield
os.environ.clear()
os.environ.update(old_environ)


@pytest.fixture(autouse=True)
def reset_filesdotpy_globals():
"""coverage/files.py has some unfortunate globals. Reset them every test."""
set_relative_directory()
yield


TRACK_TESTS = False
TEST_TXT = "/tmp/tests.txt"

Expand Down
5 changes: 2 additions & 3 deletions tests/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,9 @@ def _temp_dir(self, tmpdir_factory):
# nose's caching importer can get confused. The full path prevents
# problems.
sys.path.insert(0, os.getcwd())

yield None
yield
else:
yield None
yield

def make_file(self, filename, text="", bytes=b"", newline=None):
"""Make a file. See `tests.helpers.make_file`"""
Expand Down

0 comments on commit 26b680d

Please sign in to comment.