summaryrefslogtreecommitdiff
path: root/tests/test_test_mixins.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-03-11 20:52:27 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-03-11 20:52:27 -0500
commitcdafcb0913ac238300521463436f03571ad9ae9e (patch)
treeb85192e002f9eb7f0b1ada9df1808b7b26f48d1d /tests/test_test_mixins.py
parent1d83d59ffacd0736411e492786f83953d247819f (diff)
downloadpython-coveragepy-git-cdafcb0913ac238300521463436f03571ad9ae9e.tar.gz
refactor: pull module cleaning into here
We don't need unittest_mixins' module cleaner anymore.
Diffstat (limited to 'tests/test_test_mixins.py')
-rw-r--r--tests/test_test_mixins.py27
1 files changed, 26 insertions, 1 deletions
diff --git a/tests/test_test_mixins.py b/tests/test_test_mixins.py
index b8a3ac67..028a19fd 100644
--- a/tests/test_test_mixins.py
+++ b/tests/test_test_mixins.py
@@ -4,7 +4,11 @@
"""Tests of code in tests/mixins.py"""
-from tests.mixins import TempDirMixin
+import pytest
+
+from coverage.backward import import_local_file
+
+from tests.mixins import TempDirMixin, SysPathModulesMixin
class TempDirMixinTest(TempDirMixin):
@@ -54,3 +58,24 @@ class TempDirMixinTest(TempDirMixin):
with open("binary.dat", "rb") as f:
data = f.read()
assert data == b"\x99\x33\x66hello\0"
+
+
+class SysPathModulessMixinTest(TempDirMixin, SysPathModulesMixin):
+ """Tests of SysPathModulesMixin."""
+
+ @pytest.mark.parametrize("val", [17, 42])
+ def test_module_independence(self, val):
+ self.make_file("xyzzy.py", "A = {}".format(val))
+ import xyzzy # pylint: disable=import-error
+ assert xyzzy.A == val
+
+ def test_cleanup_and_reimport(self):
+ self.make_file("xyzzy.py", "A = 17")
+ xyzzy = import_local_file("xyzzy")
+ assert xyzzy.A == 17
+
+ self.clean_local_file_imports()
+
+ self.make_file("xyzzy.py", "A = 42")
+ xyzzy = import_local_file("xyzzy")
+ assert xyzzy.A == 42