summaryrefslogtreecommitdiff
path: root/tests/test_process.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_process.py')
-rw-r--r--tests/test_process.py30
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/test_process.py b/tests/test_process.py
index 18564cb..70329b5 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -585,6 +585,30 @@ class ProcessTest(CoverageTest):
self.assertIn("Trace function changed", out)
+ def test_warn_preimported(self):
+ self.make_file("hello.py", """\
+ import goodbye
+ import coverage
+ cov = coverage.Coverage(include=["good*"])
+ cov.start()
+ print(goodbye.f())
+ cov.stop()
+ """)
+ self.make_file("goodbye.py", """\
+ def f():
+ return "Goodbye!"
+ """)
+ goodbye_path = os.path.abspath("goodbye.py")
+
+ out = self.run_command("python hello.py")
+ self.assertIn("Goodbye!", out)
+
+ msg = (
+ "Coverage.py warning: "
+ "Already imported a file that will be measured: {0} "
+ "(already-imported)").format(goodbye_path)
+ self.assertIn(msg, out)
+
def test_note(self):
if env.PYPY and env.PY3 and env.PYPYVERSION[:3] == (5, 10, 0):
# https://bitbucket.org/pypy/pypy/issues/2729/pypy3-510-incorrectly-decodes-astral-plane
@@ -676,9 +700,11 @@ class ProcessTest(CoverageTest):
pass
""")
self.make_file("run_twice.py", """\
+ import sys
import coverage
- for _ in [1, 2]:
+ for i in [1, 2]:
+ sys.stderr.write("Run %s\\n" % i)
inst = coverage.Coverage(source=['foo'])
inst.load()
inst.start()
@@ -689,6 +715,8 @@ class ProcessTest(CoverageTest):
out = self.run_command("python run_twice.py")
self.assertEqual(
out,
+ "Run 1\n"
+ "Run 2\n"
"Coverage.py warning: Module foo was previously imported, but not measured "
"(module-not-measured)\n"
)