summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-10-16 08:16:38 -0400
committerNed Batchelder <ned@nedbatchelder.com>2021-10-16 10:46:35 -0400
commit99cf3cbd331e03750e1a251d36d1849dc59b427e (patch)
treed71ea97f1488e19c3c6cb2d1851d5aec0a91cba0 /tests
parent702c927fed2b2120ed2e4aa66668170d4120ca30 (diff)
downloadpython-coveragepy-git-99cf3cbd331e03750e1a251d36d1849dc59b427e.tar.gz
feat: `coverage run` now sets the COVERAGE_RUN environment variable
Diffstat (limited to 'tests')
-rw-r--r--tests/test_process.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/test_process.py b/tests/test_process.py
index c9a2f8ee..29ce6071 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -39,7 +39,7 @@ class ProcessTest(CoverageTest):
self.run_command("coverage run mycode.py")
self.assert_exists(".coverage")
- def test_environment(self):
+ def test_tests_dir_is_importable(self):
# Checks that we can import modules from the tests directory at all!
self.make_file("mycode.py", """\
import covmod1
@@ -53,6 +53,21 @@ class ProcessTest(CoverageTest):
self.assert_exists(".coverage")
assert out == 'done\n'
+ def test_coverage_run_envvar_is_in_coveragerun(self):
+ # Test that we are setting COVERAGE_RUN when we run.
+ self.make_file("envornot.py", """\
+ import os
+ print(os.environ.get("COVERAGE_RUN", "nope"))
+ """)
+ self.del_environ("COVERAGE_RUN")
+ # Regular Python doesn't have the environment variable.
+ out = self.run_command("python envornot.py")
+ assert out == "nope\n"
+ self.del_environ("COVERAGE_RUN")
+ # But `coverage run` does have it.
+ out = self.run_command("coverage run envornot.py")
+ assert out == "true\n"
+
def make_b_or_c_py(self):
"""Create b_or_c.py, used in a few of these tests."""
# "b_or_c.py b" will run 6 lines.