diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-19 23:08:48 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2010-02-19 23:08:48 -0500 |
commit | 86f65fd21d59fdd4febdab308e907976ca1dce6d (patch) | |
tree | 2b0bb6b5c888299f2ed17583115b46e6886d1710 /test/test_process.py | |
parent | 36a637f828d6596d0e83b6aa324f4f5f023eb16b (diff) | |
download | python-coveragepy-git-86f65fd21d59fdd4febdab308e907976ca1dce6d.tar.gz |
If the product code throws an exception, 'coverage run' now produces the same traceback as 'python' would, without the coverage-internal frames distracting from your code.
Diffstat (limited to 'test/test_process.py')
-rw-r--r-- | test/test_process.py | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/test/test_process.py b/test/test_process.py index 814a80d9..b8ccb942 100644 --- a/test/test_process.py +++ b/test/test_process.py @@ -1,6 +1,6 @@ """Tests for process behavior of coverage.py.""" -import os, sys +import os, sys, textwrap import coverage sys.path.insert(0, os.path.split(__file__)[0]) # Force relative import for Py3k @@ -148,3 +148,30 @@ class ProcessTest(CoverageTest): out = self.run_command("coverage run xyzzy.py") self.assertRegexpMatches(out, "No file to run: .*xyzzy.py") self.assertFalse("Traceback" in out) + + def test_code_throws(self): + self.make_file("throw.py", """\ + def f1(): + raise Exception("hey!") + + def f2(): + f1() + + f2() + """) + + out = self.run_command("coverage run throw.py") + # Different versions of Python report the module-level code differently + # in tracebacks, so canononicalize it. + out = out.replace(", in ?", ", in <module>") + expected = textwrap.dedent("""\ + Traceback (most recent call last): + File "throw.py", line 7, in <module> + f2() + File "throw.py", line 5, in f2 + f1() + File "throw.py", line 2, in f1 + raise Exception("hey!") + Exception: hey! + """) + self.assertMultiLineEqual(out, expected) |