Issue #9936: Fixed executable lines' search in the trace module.
diff --git a/Lib/test/test_trace.py b/Lib/test/test_trace.py
index 6c483f8..48fc0ab 100644
--- a/Lib/test/test_trace.py
+++ b/Lib/test/test_trace.py
@@ -188,7 +188,6 @@
}
self.assertEqual(tracer.results().counts, expected)
-
class TestRunExecCounts(unittest.TestCase):
"""A simple sanity test of line-counting, via runctx (exec)"""
def setUp(self):
@@ -285,8 +284,9 @@
rmtree(TESTFN)
unlink(TESTFN)
- def _coverage(self, tracer):
- tracer.run('from test import test_pprint; test_pprint.test_main()')
+ def _coverage(self, tracer,
+ cmd='from test import test_pprint; test_pprint.test_main()'):
+ tracer.run(cmd)
r = tracer.results()
r.write_results(show_missing=True, summary=True, coverdir=TESTFN)
@@ -313,6 +313,25 @@
files = os.listdir(TESTFN)
self.assertEquals(files, [])
+ def test_issue9936(self):
+ tracer = trace.Trace(trace=0, count=1)
+ modname = 'test.tracedmodules.testmod'
+ # Ensure that the module is executed in import
+ if modname in sys.modules:
+ del sys.modules[modname]
+ cmd = ("import test.tracedmodules.testmod as t;"
+ "t.func(0); t.func2();")
+ with captured_stdout() as stdout:
+ self._coverage(tracer, cmd)
+ stdout.seek(0)
+ stdout.readline()
+ coverage = {}
+ for line in stdout:
+ lines, cov, module = line.split()[:3]
+ coverage[module] = (int(lines), int(cov[:-1]))
+ self.assertIn(modname, coverage)
+ self.assertEqual(coverage[modname], (5, 100))
+
def test_main():
run_unittest(__name__)
diff --git a/Lib/test/tracedmodules/testmod.py b/Lib/test/tracedmodules/testmod.py
index a4c25e4..642776e 100644
--- a/Lib/test/tracedmodules/testmod.py
+++ b/Lib/test/tracedmodules/testmod.py
@@ -1,3 +1,9 @@
def func(x):
b = x + 1
return b + 2
+
+def func2():
+ """Test function for issue 9936 """
+ return (1,
+ 2,
+ 3)