René's URL Explorer Experiment


Title: Refactor test.libregrtest · Issue #109162 · python/cpython · GitHub

Open Graph Title: Refactor test.libregrtest · Issue #109162 · python/cpython

X Title: Refactor test.libregrtest · Issue #109162 · python/cpython

Description: I propose to refactor test.libregrtest to make it easier to maintain and to prepare adding type annotations. The regrtest project has a long history. It was added in 1996 by commit 152494a. When it was created, it was 170 lines long and ...

Open Graph Description: I propose to refactor test.libregrtest to make it easier to maintain and to prepare adding type annotations. The regrtest project has a long history. It was added in 1996 by commit 152494a. When it...

X Description: I propose to refactor test.libregrtest to make it easier to maintain and to prepare adding type annotations. The regrtest project has a long history. It was added in 1996 by commit 152494a. When it...

Opengraph URL: https://github.com/python/cpython/issues/109162

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Refactor test.libregrtest","articleBody":"I propose to refactor ``test.libregrtest`` to make it easier to maintain and to prepare adding type annotations.\r\n\r\nThe regrtest project has a long history. It was added in 1996 by commit 152494aea24669a3d74460fa460a4ed45696bc75. When it was created, it was 170 lines long and had 4 command line options: ``-v`` (verbose), ``-q`` (quiet), ``-g`` (generate) and ``-x`` (exclude). Slowly, it got more and more features:\r\n\r\n* Better command line interface with ``argparse`` (it used ``getopt`` at the begining)\r\n* Run tests in parallel with multiple processes (this code caused me a lot of headaches!)\r\n* Detect when the \"environment\" is altered: warnings filters, loggers, etc.\r\n* Re-run failed tests in verbose mode (now they are run in fresh processes)\r\n* Detect memory, reference and file descriptor leaks\r\n* Detect leaked files by creating a temporary directory for each test worker process\r\n* Best effort to restore the machine to its previous state: wait until threads and processes complete, remove temporary files, etc.\r\n* etc.\r\n\r\nSome of these features were implemented in ``test.support`` + ``test.libregrtest``.\r\n\r\nA few years ago, I decided to split the giant mono ``regrtest.py`` file (for example, it was 2 200 lines of Python code in Python 2.7) into sub-files (!). To make it possible, I passed ``ns`` argument which is a bag of \"global variables\" (technically, it's a ``Namespace`` class, see ``cmdline.py``).\r\n\r\nThe problem is that for type annotation, it's very unclear what a Namespace contains. It may or may not have arguments (see my commit message of this PR: ``Add missing attributes to Namespace: coverage, threshold, wait.``), argument types are weakly defined, etc. Moreover, ``ns`` is not only used to \"get\" variables, but also to **set** variables! For example, find_tests() overrides ``ns.args``. How is it possible to know which ``ns`` attributes are used? Are they \"read-only\"? We don't know just by reading a function prototype.\r\n\r\nThis large refactoring cleans up everything in a serie of small changes to pass simple types like ``bool``, ``str`` or ``tuple[str]``. It's easier to guess the purpose of a function and its behavior just from its prototype.\r\n\r\nI tried to create only short files, the longest is still sadly ``main.py`` with 891 lines.\r\n\r\n```\r\n$ wc -l *.py|sort -n\r\n     2 __init__.py\r\n    56 pgo.py\r\n   124 win_utils.py\r\n   159 setup.py\r\n   202 refleak.py\r\n   307 utils.py\r\n   329 save_env.py\r\n   451 cmdline.py\r\n   575 runtest.py\r\n   631 runtest_mp.py\r\n   891 main.py\r\n  3727 total\r\n```\r\n\r\nTo understand where the ``ns`` magic bag of global variables, look at ``regrtest.py`` monster in Python 2.7. Its main() functions defines not less than 34 functions inside the main() function! Variables are defined in the main() prototype!\r\n\r\n```\r\ndef main(tests=None, testdir=None, verbose=0, quiet=False,\r\n         exclude=False, single=False, randomize=False, fromfile=None,\r\n         findleaks=False, use_resources=None, trace=False, coverdir='coverage',\r\n         runleaks=False, huntrleaks=False, verbose2=False, print_slow=False,\r\n         random_seed=None, use_mp=None, verbose3=False, forever=False,\r\n         header=False, pgo=False, failfast=False, match_tests=None):\r\n```\r\n\r\nI supposed that it was designed to be able to use regrtest as an API: pass parameters to the main() function, without having to use the command line interface. In the main branch, this feature is still supported, the magic ``**kwargs`` bag:\r\n\r\n```py\r\ndef main(tests=None, **kwargs):\r\n    Regrtest().main(tests=tests, **kwargs)\r\n```\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-109163\r\n* gh-109168\r\n* gh-109170\r\n* gh-109171\r\n* gh-109172\r\n* gh-109177\r\n* gh-109202\r\n* gh-109204\r\n* gh-109205\r\n* gh-109206\r\n* gh-109208\r\n* gh-109212\r\n* gh-109229\n* gh-109243\n* gh-109246\n* gh-109248\n* gh-109250\n* gh-109253\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/vstinner","@type":"Person","name":"vstinner"},"datePublished":"2023-09-08T21:58:25.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/109162/cpython/issues/109162"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:ebf55b8c-eaa0-1eb0-54a8-28ecbc9f4437
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD97E:C8A64:706656:9BA701:696A7D23
html-safe-nonce633ecd1e2f272f1d9903448b49c40f16cd6a9f66762e2c4a25f6dc17f6c98b2e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTdFOkM4QTY0OjcwNjY1Njo5QkE3MDE6Njk2QTdEMjMiLCJ2aXNpdG9yX2lkIjoiNjA0NDAzMDc2NTU3MTQwNzEzOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac87b75df5a63c0de72ae04c116e3b2d3f7dcae05a822a6630cf69d07f9731e806
hovercard-subject-tagissue:1888404839
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/109162/issue_layout
twitter:imagehttps://opengraph.githubassets.com/629faae8bbcee72ad6bdf3860efff12e57744a1a7334350783b66e2e973132f9/python/cpython/issues/109162
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/629faae8bbcee72ad6bdf3860efff12e57744a1a7334350783b66e2e973132f9/python/cpython/issues/109162
og:image:altI propose to refactor test.libregrtest to make it easier to maintain and to prepare adding type annotations. The regrtest project has a long history. It was added in 1996 by commit 152494a. When it...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamevstinner
hostnamegithub.com
expected-hostnamegithub.com
None5b774e44f85c14a75886edd04ddda4e5a25ddebbb241bcbb590b08a3048730e8
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasecc5f4eee261b3601c1e98e217ceaf28508b9567e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/issues/109162#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F109162
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F109162
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/109162
Reloadhttps://github.com/python/cpython/issues/109162
Reloadhttps://github.com/python/cpython/issues/109162
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/issues/109162
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/issues/109162
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/109162
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/109162
Refactor test.libregrtesthttps://github.com/python/cpython/issues/109162#top
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
https://github.com/vstinner
https://github.com/vstinner
vstinnerhttps://github.com/vstinner
on Sep 8, 2023https://github.com/python/cpython/issues/109162#issue-1888404839
152494ahttps://github.com/python/cpython/commit/152494aea24669a3d74460fa460a4ed45696bc75
gh-109162: Refactor Regrtest.main() #109163https://github.com/python/cpython/pull/109163
gh-109162: Regrtest copies 'ns' attributes #109168https://github.com/python/cpython/pull/109168
gh-109162: Refactor Regrtest.action_run_tests() #109170https://github.com/python/cpython/pull/109170
gh-109162: Refactor libregrtest WorkerJob #109171https://github.com/python/cpython/pull/109171
gh-109162: Refactor libregrtest.runtest #109172https://github.com/python/cpython/pull/109172
gh-109162: Refactor libregrtest.RunTests #109177https://github.com/python/cpython/pull/109177
gh-109162: libregrtest: fix _decode_worker_job() #109202https://github.com/python/cpython/pull/109202
gh-109162: libregrtest: remove WorkerJob class #109204https://github.com/python/cpython/pull/109204
gh-109162: Refactor libregrtest.runtest_mp #109205https://github.com/python/cpython/pull/109205
gh-109162: Refactor libregrtest.Regrtest #109206https://github.com/python/cpython/pull/109206
gh-109162: libregrtest: add TestResults class #109208https://github.com/python/cpython/pull/109208
gh-109162: libregrtest: add Logger class #109212https://github.com/python/cpython/pull/109212
gh-109162: libregrtest: add worker.py #109229https://github.com/python/cpython/pull/109229
gh-109162: libregrtest: add single.py and result.py #109243https://github.com/python/cpython/pull/109243
gh-109162: libregrtest: fix Logger #109246https://github.com/python/cpython/pull/109246
gh-109162: libregrtest: rename runtest_mp.py to run_workers.py #109248https://github.com/python/cpython/pull/109248
gh-109162: libregrtest: use relative imports #109250https://github.com/python/cpython/pull/109250
gh-109162: libregrtest: move code around #109253https://github.com/python/cpython/pull/109253
testsTests in the Lib/test dirhttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22tests%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.