summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.txt9
-rw-r--r--coverage/control.py9
-rw-r--r--tests/test_process.py25
3 files changed, 37 insertions, 6 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index aaf2da7b..b0004b5c 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,15 @@ Change history for Coverage.py
------------------------------
+Latest
+------
+
+- A new warning is possible, if a desired file isn't measure because it was
+ imported before coverage was started (`issue 353`_).
+
+.. _issue 353: https://bitbucket.org/ned/coveragepy/issue/353/40a3-introduces-an-unexpected-third-case
+
+
Version 4.0a4 --- 25 January 2015
---------------------------------
diff --git a/coverage/control.py b/coverage/control.py
index 197a7c1e..319f56dc 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -722,12 +722,9 @@ class Coverage(object):
):
self._warn("Module %s has no Python source." % pkg)
else:
- raise AssertionError(
- "Unexpected third case: name = %s, "
- "object = %r, "
- "__file__ = %s" % (
- pkg, sys.modules[pkg], sys.modules[pkg].__file__
- )
+ self._warn(
+ "Module %s was previously imported, "
+ "but not measured." % pkg
)
# Find out if we got any data.
diff --git a/tests/test_process.py b/tests/test_process.py
index a1c853d1..43fdc1bd 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -568,6 +568,31 @@ class ProcessTest(CoverageTest):
out = self.run_command("python allok.py")
self.assertEqual(out, "No warnings!\n")
+ def test_run_twice(self):
+ # https://bitbucket.org/ned/coveragepy/issue/353/40a3-introduces-an-unexpected-third-case
+ self.make_file("foo.py", """\
+ def foo():
+ pass
+ """)
+ self.make_file("run_twice.py", """\
+ import coverage
+
+ for _ in [1, 2]:
+ inst = coverage.Coverage(source=['foo'])
+ inst.load()
+ inst.start()
+ import foo
+ inst.stop()
+ inst.combine()
+ inst.save()
+ """)
+ out = self.run_command("python run_twice.py")
+ self.assertEqual(
+ out,
+ "Coverage.py warning: "
+ "Module foo was previously imported, but not measured.\n"
+ )
+
class AliasedCommandTest(CoverageTest):
"""Tests of the version-specific command aliases."""