summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/coveragetest.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index d98bc6fd..c30e13a7 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -28,6 +28,44 @@ from coverage.misc import StopEverything
from tests.helpers import run_command, SuperModuleCleaner
+# TEMPORARY to see if it helps.
+class EnvironmentAwareMixin(unittest.TestCase):
+ """A test case mixin that isolates changes to the environment."""
+
+ def setUp(self):
+ super(EnvironmentAwareMixin, self).setUp()
+
+ # Record environment variables that we changed with set_environ.
+ self._environ_undos = {}
+
+ self.addCleanup(self._cleanup_environ)
+
+ def set_environ(self, name, value):
+ """Set an environment variable `name` to be `value`.
+
+ The environment variable is set, and record is kept that it was set,
+ so that `cleanup_environ` can restore its original value.
+
+ """
+ if name not in self._environ_undos:
+ self._environ_undos[name] = os.environ.get(name)
+ os.environ[name] = value
+
+ def del_environ(self, name):
+ """Delete an environment variable, unless we set it."""
+ if name not in self._environ_undos:
+ self._environ_undos[name] = os.environ.get(name)
+ del os.environ[name]
+
+ def _cleanup_environ(self):
+ """Undo all the changes made by `set_environ`."""
+ for name, value in self._environ_undos.items():
+ if value is None:
+ del os.environ[name]
+ else:
+ os.environ[name] = value
+
+
# Status returns for the command line.
OK, ERR = 0, 1
@@ -461,6 +499,9 @@ class CoverageTest(
pypath += testmods + os.pathsep + zipfile
self.set_environ(pythonpath_name, pypath)
+ self.del_environ("COVERAGE_COVERAGE")
+ self.del_environ("COVERAGE_PROCESS_START")
+
self.last_command_status, self.last_command_output = run_command(cmd)
print(self.last_command_output)
return self.last_command_status, self.last_command_output