classification
Title: trace module cli does not write cover files
Type: behavior Stage: patch review
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Michael Selik, belopolsky, berker.peksag, rhettinger, selik
Priority: normal Keywords: patch

Created on 2017-10-31 02:55 by Michael Selik, last changed 2017-11-13 22:43 by selik.

Pull Requests
URL Status Linked Edit
PR 4205 open selik, 2017-11-01 01:38
Messages (7)
msg305268 - (view) Author: Michael Selik (Michael Selik) Date: 2017-10-31 02:55
The 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 directory


My apologies if this is a duplicate bug. I searched the tracker and Google for a while, but couldn't find a relevant issue.
msg305269 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2017-10-31 04:19
It worked in Python 3.4, but not afterwards.
msg305341 - (view) Author: Michael Selik (Michael Selik) Date: 2017-10-31 22:46
The problem appears to be a mistake in commit f026dae130bf6f9015c4b212f16852ba4a3f3dec

https://github.com/python/cpython/commit/f026dae130bf6f9015c4b212f16852ba4a3f3dec

This made the writing of cover files conditional on ``show_missing`` which 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.cover
msg305343 - (view) Author: Michael Selik (Michael Selik) Date: 2017-11-01 01:10
While writing a patch for this, I noticed the ``lnotab`` parameter 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_missing`` was 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
msg305347 - (view) Author: Michael Selik (Michael Selik) Date: 2017-11-01 01:51
Ok, pull request submitted:
https://github.com/python/cpython/pull/4205
msg305367 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-11-01 10:50
I think the first part of your patch also fixes issue 26818. Could you adapt the test there and add a test case for the problem in this issue?
msg306173 - (view) Author: Michael Selik (selik) * Date: 2017-11-13 22:43
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)
+

?
History
Date User Action Args
2017-11-13 22:43:51seliksetmessages: + msg306173
2017-11-13 22:41:21seliksetnosy: + selik
2017-11-01 10:50:25berker.peksagsetnosy: + berker.peksag

messages: + msg305367
versions: - Python 3.5
2017-11-01 05:09:27rhettingersetnosy: + belopolsky
2017-11-01 01:51:48Michael Seliksetmessages: + msg305347
2017-11-01 01:38:25seliksetkeywords: + patch
stage: patch review
pull_requests: + pull_request4174
2017-11-01 01:10:39Michael Seliksetmessages: + msg305343
2017-10-31 22:46:10Michael Seliksetmessages: + msg305341
2017-10-31 04:19:24rhettingersetversions: + Python 3.5, Python 3.7
nosy: + rhettinger

messages: + msg305269

components: + Library (Lib)
2017-10-31 02:55:06Michael Selikcreate