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

test_cmd has test_coverage that does not work #111426

Closed
sobolevn opened this issue Oct 28, 2023 · 0 comments
Closed

test_cmd has test_coverage that does not work #111426

sobolevn opened this issue Oct 28, 2023 · 0 comments
Assignees
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@sobolevn
Copy link
Member

sobolevn commented Oct 28, 2023

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

@sobolevn sobolevn added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Oct 28, 2023
@sobolevn sobolevn self-assigned this Oct 28, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Oct 28, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 28, 2023
(cherry picked from commit 66bea25)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 28, 2023
(cherry picked from commit 66bea25)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
AlexWaygood pushed a commit that referenced this issue Oct 28, 2023
gh-111426: Remove `test_cmd.test_coverage` (GH-111427)
(cherry picked from commit 66bea25)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
AlexWaygood pushed a commit that referenced this issue Oct 28, 2023
gh-111426: Remove `test_cmd.test_coverage` (GH-111427)
(cherry picked from commit 66bea25)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
iritkatriel pushed a commit to iritkatriel/cpython that referenced this issue Oct 29, 2023
aisk pushed a commit to aisk/cpython that referenced this issue Feb 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants