Skip to content

test_cmd has test_coverage that does not work#111426

@sobolevn

Description

@sobolevn

Bug report

deftest_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"insys.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:

deftest_coverage(coverdir): fromtest.supportimportimport_helpertrace=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

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