diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2021-11-17 22:08:41 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2021-11-17 22:09:52 -0500 |
commit | 26b680d3d4253258161f1a20d556fbf3f3622581 (patch) | |
tree | 9febea3a5dbfbe1480a94f4214e09773ae59d875 | |
parent | ad1fcae833aeeae38db9764e61eeff48aa048dff (diff) | |
download | python-coveragepy-git-26b680d3d4253258161f1a20d556fbf3f3622581.tar.gz |
test: properly reset a few globals between every test
-rw-r--r-- | tests/conftest.py | 17 | ||||
-rw-r--r-- | tests/mixins.py | 5 |
2 files changed, 19 insertions, 3 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 6ef42fc1..581329bb 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,6 +16,7 @@ import pytest 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. @@ -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" diff --git a/tests/mixins.py b/tests/mixins.py index e55a05b9..25663c6e 100644 --- a/tests/mixins.py +++ b/tests/mixins.py @@ -66,10 +66,9 @@ class TempDirMixin: # 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`""" |