-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-75117: IDLE - add script for running coverage on tests #22694
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
base: main
Are you sure you want to change the base?
gh-75117: IDLE - add script for running coverage on tests #22694
Conversation
I haven't looked properly at it yet, but:
|
Where? Could you leave a specific comment on the relevant lines?
Yes, if we agree that this is the way to go, and on some details such as the file name and location. |
@E-Paine, many thanks for the review and great comments! 🙏 |
@terryjreedy, this is now definitely ready for your review :) |
I was looking for something to add to, not replace, a revised version of what I already wrote. So I probably will want this patch to leave README alone so I can deal with it in a followup PR. But I will defer that until we finish the sidebar patch. |
This PR is stale because it has been open for 30 days with no activity. |
Looks good after first read-through. Should mention that this only works with in-tree builds. |
(Updating branch to trigger the new CLA check) |
Thanks for the review @erlend-aasland! Feel free to remove the parts that open the report in a browser, and instead just print the path to the HTML file. We should likely get @terryjreedy's blessing before merging this, though. (Something is very wrong with the CLA bot if it doesn't know that I've signed the CLA...) |
Since webbrowser seems to be broken, or at least problematic, on macOS, the most consistent thing to do is just to remove that functionality. I can update the PR.
@ambv ☝🏻 |
@taleinat sorry for the mishap. You used to use |
Thanks, Łukasz! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think coveragerc should be extracted to a file first. I can do it easier since I can just copy my current file.
(There were several before modules were renamed, now only one is left.) | ||
To get a coverage report for a specific module's tests, run: | ||
|
||
python Lib/idlelib/idle_test/run_coverage.py <module_name> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cd ..
cover tooltip
shows me the htmlcov/index.html in about a second, faster than I can type the above. How long does the above run with tooltip?
To get a coverage report for IDLE's entire test suite, run the | ||
above command with "all" instead of a module name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which of two possible meanings of 'all' is used?
- Run each test_x separately and report the coverage for each module the same as if only that test file were run.
- Run all tests together and report the coverage for each module that result from running all tests (as well as the collective coverage).
I believe using coverage option-L
gives me the second.
To get a coverage report for IDLE's entire test suite, run the | ||
above command with "all" instead of a module name. | ||
|
||
Note: this does not work with out-of-tree builds yet. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean installed python or something else?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds testing for the IDLE test suite in the source directory. I'm one of those folks who like to keep my git clone clean, so I use a build directory outside of the repo directory (AKA an out-of-tree build).
$ cd cpython.git
$ git clean -fdx
$ mkdir ../build
$ cd ../build
$ ../cpython.git/configure && make
$ ./python.exe ../cpython.git/Lib/idlelib/idle_test/run_coverage.py # <= will not work
$ cd cpython.git
$ git clean -fdx
$ ./configure && make
$ ./python.exe Lib/idlelib/idle_test/run_coverage.py # <= ok
I guess you could use an installed Python to check the coverage of the IDLE test suite in your development environment. I'm not sure why you would want to do so, though.
|
||
.*# htest # |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The readme is behind the file I actually use.
.*# htest # | |
.*# pragma: no cover | |
.*# pragma: no branch | |
.*# htest # | |
if not (_htest or _utest): |
The pragmas are generic to coverage; 'no cover' is currently used in idlelib.
The suggested coveragerc should be a separate file in idle_test/. If I knew how to put a symlink in /dev, where I use it, I would to avoid the 2 copies issues.
--- | ||
The second parameter was added for tests of module x not named test_x. | ||
(There were several before modules were renamed, now only one is left.) | ||
To get a coverage report for a specific module's tests, run: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify what I meant 2 years ago, DO NOT REMOVE the instructions for what I have done since 3.6 and plan to continue to use. What I deferred then was revising my text. I am working on it now.
To get a coverage report for a specific module's tests, run: | |
To get a coverage report for a specific module's tests, do one of the following: | |
A. run |
I can then edit my part to starts B. ...
.
When you're done making the requested changes, leave the comment: |
@taleinat, all's good now. |
This adds a cross-platform script for generating coverage info for any single IDLE module or for all of IDLE.
The script uses a dedicated venv in
Lib/idlelib/test_idle/coverage_venv/
, creating it if not found. Thecoverage
package is installed into this venv.The script also writes a temporary
.coveragerc
file to ignore irrelevant code. If an existing.coveragerc
exists, it is temporarily overwritten.This is heavily based on @terryjreedy's instructions in
Lib/idlelib/test_idle/README
, adapted to be cross-platform and hopefully robust in terms of where it is run from and where it leaves files lying around.This has currently only been tested on Ubuntu 20.04, and should be tested on macOS and Windows.