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

bpo-4080: unittest durations #12271

Merged
merged 50 commits into from
Apr 2, 2023
Merged

bpo-4080: unittest durations #12271

merged 50 commits into from
Apr 2, 2023

Conversation

giampaolo
Copy link
Contributor

@giampaolo giampaolo commented Mar 11, 2019

Adds cmdline option to show unit-tests durations + summary of the slowest ones, see https://bugs.python.org/issue4080.

Top 5 slowest ones:

$ ./python -m unittest Lib.test.test_ftplib --durations=5 
..........................................s.............................................
Slowest test durations
----------------------------------------------------------------------
0.203s     test_with_statement (Lib.test.test_ftplib.TestFTPClass)
0.204s     test_retrbinary_rest (Lib.test.test_ftplib.TestTLS_FTPClassMixin)
0.214s     test_with_statement (Lib.test.test_ftplib.TestTLS_FTPClassMixin)
0.881s     test_mlsd (Lib.test.test_ftplib.TestFTPClass)
1.162s     test_mlsd (Lib.test.test_ftplib.TestTLS_FTPClassMixin)

----------------------------------------------------------------------
Ran 88 tests in 5.264s

OK (skipped=1)

All + individual elapsed time:

$ ./python -m unittest Lib.test.test_ftplib --durations=0 -v
test_abort (Lib.test.test_ftplib.TestFTPClass) ... [0.002s] ok
test_all_errors (Lib.test.test_ftplib.TestFTPClass) ... [0.001s] ok
test_cwd (Lib.test.test_ftplib.TestFTPClass) ... [0.001s] ok
test_delete (Lib.test.test_ftplib.TestFTPClass) ... [0.001s] ok
test_dir (Lib.test.test_ftplib.TestFTPClass) ... [0.041s] ok
test_mlsd (Lib.test.test_ftplib.TestFTPClass) ... [0.880s] ok
test_nlst (Lib.test.test_ftplib.TestFTPClass) ... [0.092s] ok
test_parse257 (Lib.test.test_ftplib.TestFTPClass) ... [0.002s] ok
...

Slowest test durations
----------------------------------------------------------------------
0.000s     test__all__ (Lib.test.test_ftplib.MiscTestCase)
0.002s     test_pwd (Lib.test.test_ftplib.TestFTPClass)
....
0.140s     test_storbinary_rest (Lib.test.test_ftplib.TestTLS_FTPClassMixin)
0.148s     test_data_connection (Lib.test.test_ftplib.TestTLS_FTPClass)
0.154s     test_storlines (Lib.test.test_ftplib.TestTLS_FTPClassMixin)
0.175s     test_retrbinary_rest (Lib.test.test_ftplib.TestTLS_FTPClassMixin)
0.204s     test_with_statement (Lib.test.test_ftplib.TestFTPClass)
0.208s     test_with_statement (Lib.test.test_ftplib.TestTLS_FTPClassMixin)
0.880s     test_mlsd (Lib.test.test_ftplib.TestFTPClass)
1.281s     test_mlsd (Lib.test.test_ftplib.TestTLS_FTPClassMixin)

----------------------------------------------------------------------
Ran 88 tests in 5.396s

OK (skipped=1)

https://bugs.python.org/issue4080

Lib/unittest/runner.py Outdated Show resolved Hide resolved
Doc/library/unittest.rst Outdated Show resolved Hide resolved
@iritkatriel iritkatriel requested a review from gpshead November 25, 2022 12:14
@giampaolo
Copy link
Contributor Author

@LiteApplication thanks for approving. Merging.

@giampaolo giampaolo merged commit 6883007 into python:main Apr 2, 2023
@giampaolo giampaolo deleted the unittest-durations branch April 2, 2023 22:13
@eggplants
Copy link

@giampaolo @LiteApplication doesn't appear to be a regular Python reviewer, is it no problem to merge?

@bedevere-bot

This comment was marked as off-topic.

@terryjreedy
Copy link
Member

Hidden buildbot failure was for test_asyncio. I presume unrelated since random test_asyncio failures are unfortunately routine.

Doc/library/unittest.rst Show resolved Hide resolved
Lib/test/test_unittest/test_runner.py Show resolved Hide resolved
Lib/unittest/result.py Show resolved Hide resolved
@giampaolo
Copy link
Contributor Author

giampaolo commented Apr 3, 2023

I created #103209 to address @gpshead's post-merge comments to this PR.

@giampaolo
Copy link
Contributor Author

@eggplants wrote:

@giampaolo @LiteApplication doesn't appear to be a regular Python reviewer, is it no problem to merge?

Sorry, I didn't realize that. This was an old PR that unfortunately never received much attention, so it stayed idle for a long time and I occasionally updated it to fix merge conflicts. When I finally saw an approval I was just happy to see it and merged it without further checking. FWIW, I went through these changes multiple times over the last 4 years: I'm confident that the changes introduced in here are OK and are fully retro compatible (this probably was the most sensitive part to consider).

@eggplants
Copy link

Anyway, I am glad this feature has finally been merged. Thank you @giampaolo -san.

@giampaolo
Copy link
Contributor Author

Here's a nose issue related to this PR's retro-compatibility: nose-devs/nose2#569.
nose extended TestCase class without defining the new addDuration method. Python 3.12 emitted a warning but it didn't crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.