Skip to content

test_cmd has test_coverage that does not work #111426

Closed

Description

@sobolevn

Bug report

def test_coverage(coverdir):
trace = support.import_module('trace')
tracer=trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,],
trace=0, count=1)
tracer.run('import importlib; importlib.reload(cmd); test_main()')
r=tracer.results()
print("Writing coverage results...")
r.write_results(show_missing=True, summary=True, coverdir=coverdir)
if __name__ == "__main__":
if "-c" in sys.argv:
test_coverage('/tmp/cmd.cover')

Output:

» ./python.exe Lib/test/test_cmd.py -c
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_cmd.py", line 262, in <module>
    test_coverage('/tmp/cmd.cover')
  File "/Users/sobolev/Desktop/cpython2/Lib/test/test_cmd.py", line 252, in test_coverage
    trace = support.import_module('trace')
            ^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'test.support' has no attribute 'import_module'

Even, if refactored to:

def test_coverage(coverdir):
    from test.support import import_helper
    trace = import_helper.import_module('trace')
    tracer=trace.Trace(ignoredirs=[sys.base_prefix, sys.base_exec_prefix,],
                        trace=0, count=1)
    tracer.run('import unittest; unittest.main()')
    r=tracer.results()
    print("Writing coverage results...")
    r.write_results(show_missing=True, summary=True, coverdir=coverdir)

It still does not work, no file is generated.

I propose to remove it, since -T works just fine:

» ./python.exe -m test -T test_cmd    
Using random seed: 2974785131
0:00:00 load avg: 1.22 Run 1 test sequentially
0:00:00 load avg: 1.22 [1/1] test_cmd

== Tests result: SUCCESS ==

1 test OK.

Total duration: 78 ms
Total tests: run=3
Total test files: run=1/1
Result: SUCCESS
lines   cov%   module   (path)
...
  236    63%   cmd   (/Users/sobolev/Desktop/cpython2/Lib/cmd.py)
...

I have a PR ready.

related #111348

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    testsTests in the Lib/test dir
    on Oct 28, 2023
  2. self-assigned this
    on Oct 28, 2023
  3. added a commit that references this issue on Oct 28, 2023
  4. added a commit that references this issue on Oct 28, 2023
  5. added 2 commits that reference this issue on Oct 28, 2023
  6. added 2 commits that reference this issue on Oct 28, 2023
  7. added a commit that references this issue on Oct 29, 2023
  8. added a commit that references this issue on Feb 11, 2024
  9. added a commit that references this issue on Sep 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions