Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trace module cli does not write cover files #76089

Closed
MichaelSelik mannequin opened this issue Oct 31, 2017 · 13 comments
Closed

trace module cli does not write cover files #76089

MichaelSelik mannequin opened this issue Oct 31, 2017 · 13 comments
Labels
3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@MichaelSelik
Copy link
Mannequin

MichaelSelik mannequin commented Oct 31, 2017

BPO 31908
Nosy @rhettinger, @abalkin, @berkerpeksag, @serhiy-storchaka, @selik, @ZackerySpytz, @miss-islington
PRs
  • bpo-31908: Fix output of cover files for trace module command-line tool #4205
  • [3.7] bpo-31908: Fix output of cover files for trace module command-line tool. (GH-4205) #6666
  • [3.6] bpo-31908: Fix output of cover files for trace module command-line tool. (GH-4205) #6667
  • [3.6] bpo-31908: Fix output of cover files for trace module command-line tool. (GH-4205) #6668
  • bpo-26818: Add a test to make sure the bug is fixed #8664
  • [3.7] bpo-26818: Add a test to make sure the bug is fixed (GH-8664) #8732
  • 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:

    assignee = None
    closed_at = None
    created_at = <Date 2017-10-31.02:55:06.847>
    labels = ['3.7', 'type-bug', 'library']
    title = 'trace module cli does not write cover files'
    updated_at = <Date 2018-08-11.06:28:37.697>
    user = 'https://bugs.python.org/MichaelSelik'

    bugs.python.org fields:

    activity = <Date 2018-08-11.06:28:37.697>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2017-10-31.02:55:06.847>
    creator = 'Michael Selik'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31908
    keywords = ['patch']
    message_count = 13.0
    messages = ['305268', '305269', '305341', '305343', '305347', '305367', '306173', '315980', '315981', '315984', '323058', '323401', '323403']
    nosy_count = 8.0
    nosy_names = ['rhettinger', 'belopolsky', 'berker.peksag', 'serhiy.storchaka', 'selik', 'Michael Selik', 'ZackerySpytz', 'miss-islington']
    pr_nums = ['4205', '6666', '6667', '6668', '8664', '8732']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue31908'
    versions = ['Python 3.6', 'Python 3.7']

    @MichaelSelik
    Copy link
    Mannequin Author

    MichaelSelik mannequin commented Oct 31, 2017

    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.

    @MichaelSelik MichaelSelik mannequin added the type-bug An unexpected behavior, bug, or error label Oct 31, 2017
    @rhettinger
    Copy link
    Contributor

    It worked in Python 3.4, but not afterwards.

    @rhettinger rhettinger added stdlib Python modules in the Lib dir 3.7 (EOL) end of life labels Oct 31, 2017
    @MichaelSelik
    Copy link
    Mannequin Author

    MichaelSelik mannequin commented Oct 31, 2017

    The problem appears to be a mistake in commit f026dae

    f026dae

    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
    

    @MichaelSelik
    Copy link
    Mannequin Author

    MichaelSelik mannequin commented Nov 1, 2017

    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

    @MichaelSelik
    Copy link
    Mannequin Author

    MichaelSelik mannequin commented Nov 1, 2017

    Ok, pull request submitted:
    #4205

    @berkerpeksag
    Copy link
    Member

    I 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?

    @selik
    Copy link
    Mannequin

    selik mannequin commented Nov 13, 2017

    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)
    +

    ?

    @serhiy-storchaka
    Copy link
    Member

    New changeset 47ab154 by Serhiy Storchaka (Michael Selik) in branch 'master':
    bpo-31908: Fix output of cover files for trace module command-line tool. (GH-4205)
    47ab154

    @miss-islington
    Copy link
    Contributor

    New changeset e4eeb6e by Miss Islington (bot) in branch '3.7':
    bpo-31908: Fix output of cover files for trace module command-line tool. (GH-4205)
    e4eeb6e

    @miss-islington
    Copy link
    Contributor

    New changeset a607f8b by Miss Islington (bot) in branch '3.6':
    bpo-31908: Fix output of cover files for trace module command-line tool. (GH-4205)
    a607f8b

    @ZackerySpytz
    Copy link
    Mannequin

    ZackerySpytz mannequin commented Aug 3, 2018

    This change causes test_trace to leave a trace.cover file in the Lib directory (see bpo-34171).

    @berkerpeksag
    Copy link
    Member

    New changeset c8b0dbc by Berker Peksag in branch 'master':
    bpo-26818: Add a test to make sure the bug is fixed (GH-8664)
    c8b0dbc

    @berkerpeksag
    Copy link
    Member

    New changeset 8fc21c8 by Berker Peksag (Miss Islington (bot)) in branch '3.7':
    bpo-26818: Add a test to make sure the bug is fixed (GH-8664)
    8fc21c8

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    4 participants