From 6c9ac4a84b53a2d8ca36c3cdc5decd965d24b04d Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Tue, 20 Feb 2018 08:26:35 -0500 Subject: A new warning for files already imported before coverage starts --- tests/test_process.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'tests/test_process.py') diff --git a/tests/test_process.py b/tests/test_process.py index 35dddd07..70329b59 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 -- cgit v1.2.1