Repository navigation
trace module cli does not write cover files #76089
Description
Activity
MichaelSelik commented
on Oct 31, 2017 MichaelSelikmannequinMannequinAuthorMore actionsThe trace module command-line utility doesn't write cover files. I've noticed this issue for some years now. It works fine in Python 2. When using Python 3, no ".cover" files are written, regardless of how "--coverdir" is specified.
mike on macbook in ~/ $ echo 'print("hello")' > foo.py mike on macbook in ~/ $ python -m trace --count foo.py hello mike on macbook in ~/ $ ls *.cover ls: *.cover: No such file or directoryMy apologies if this is a duplicate bug. I searched the tracker and Google for a while, but couldn't find a relevant issue.
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Oct 31, 2017 It worked in Python 3.4, but not afterwards.
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory3.7 (EOL)end of lifeend of life
on Oct 31, 2017 MichaelSelik commented
on Oct 31, 2017 MichaelSelikmannequinMannequinAuthorMore actionsThe problem appears to be a mistake in commit f026dae
This made the writing of cover files conditional on
show_missingwhich is the option to mark lines which weren't executed with several angle brackets ">>>>>".https://github.com/python/cpython/blob/3.5/Lib/trace.py#L326
mike on mac in ~/ $ python -m trace --count foo.py hello mike on mac in ~/ $ ls *.cover ls: *.cover: No such file or directory mike on mac in ~/ $ python -m trace --count -m foo.py hello mike on mac in ~/ $ ls *.cover -rw-r--r-- 1 mike staff 22B Oct 31 15:40 foo.coverMichaelSelik commented
on Nov 1, 2017 MichaelSelikmannequinMannequinAuthorMore actionsWhile writing a patch for this, I noticed the
lnotabparameter seems nearly unused. It's a dict, but is only used for its keys.https://github.com/python/cpython/blob/master/Lib/trace.py#L333
Further, the choice to count unreached lines only when
show_missingwas set seems inconsistent.https://github.com/python/cpython/blob/master/Lib/trace.py#L335
https://github.com/python/cpython/blob/master/Lib/trace.py#L280
MichaelSelik commented
on Nov 1, 2017 MichaelSelikmannequinMannequinAuthorMore actionsOk, pull request submitted:
#4205I think the first part of your patch also fixes bpo-26818. Could you adapt the test there and add a test case for the problem in this issue?
You're referring to something like this:
+ def test_count_and_summary(self):
+ name = TESTFN + '.py'
+ with open(name, 'w') as fd:
+ self.addCleanup(unlink, name)
+ fd.write("""\
+x = 1
+y = 2
+
+def f():
+ return x + y
+
+for i in range(10):
+ f()
+ """)
+ status, stdout, stderr = assert_python_ok('-m', 'trace', '-cs', name)
+ self.assertEqual(status, 0)
+ self.assertIn(b'lines cov% module (path)', stdout)
+ self.assertIn(('6 100%% %s (%s)' % (TESTFN, name)).encode(), stdout)
+?
This change causes test_trace to leave a trace.cover file in the Lib directory (see bpo-34171).
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: