René's URL Explorer Experiment


Title: bpo-32972: Add unittest.AsyncioTestCase by dave-shawley · Pull Request #10296 · python/cpython · GitHub

Open Graph Title: bpo-32972: Add unittest.AsyncioTestCase by dave-shawley · Pull Request #10296 · python/cpython

X Title: bpo-32972: Add unittest.AsyncioTestCase by dave-shawley · Pull Request #10296 · python/cpython

Description: This PR adds co-routine support to unittest by adding a new sub-class of unittest.TestCase named unittest.AsyncioTestCase. It extends unittest.TestCase by adding the following functionality: a new event loop is created and terminated with each test method & the same event loop is used throughout the entire test method execution from setup through cleanup asynchronous test setup and teardown are supported by new methods - asyncSetUp and asyncTearDown test methods that are decorated with the async keyword are run on the event loop. Undecorated methods are run as normal methods. cleanup hooks that are decorated with the async keyword are run on the event loop. Undecorated methods are run as normal methods. I made the following conscious decisions during the implementation that may be somewhat controversial so I want to mention them here (in no particular order) along with the rationale. there is no direct support for other event loop implementation: other event loop implementations can be plugged in using a custom EventLoopPolicy implementation. It can be inserted by overriding setUpClass. I believe that other loop implementations can either plug in using the event loop policy or provide their own asynchronous test case implementation (e.g., tornado.testing). asyncio.iscoroutine is used to detect async methods: the two places that I need to detect whether a callable is a co-routine or not are: (a) test methods and (b) cleanup hooks added with addCleanup. Both are explicit (opt-in) actions so they are completely controlled by the test writer. outstanding asyncio Tasks are not terminated: I'm still on the fence about whether the test should fail if there are outstanding tasks or if it should gather them. async test case is a separate class: I decided to use a sub-class so that it is immediately obvious that a test methods are intended to run on the event loop. This also insulates unittest.TestCase from unexpected breakages and maintains it's current behavior. Open Questions What should happen when len(asyncio.all_tasks()) is non-zero after cleanups are run? Should unittest.AsyncioTestCase include a global test run timeout? I still have to amend commits to update documentation but I wanted to have the discussion about the implementation choices before I started writing up examples and updating the existing documentation suite. https://bugs.python.org/issue32972

Open Graph Description: This PR adds co-routine support to unittest by adding a new sub-class of unittest.TestCase named unittest.AsyncioTestCase. It extends unittest.TestCase by adding the following functionality: a ne...

X Description: This PR adds co-routine support to unittest by adding a new sub-class of unittest.TestCase named unittest.AsyncioTestCase. It extends unittest.TestCase by adding the following functionality: a ne...

Opengraph URL: https://github.com/python/cpython/pull/10296

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:7c2f7304-1e06-d552-5505-1cecaa0d50fc
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB640:37A072:C3ABDD:11CD399:6A5793E6
html-safe-nonce96675fbcc659d90c0c26de60529a00345d0c75bea95a60c2ce5e29c633311365
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNjQwOjM3QTA3MjpDM0FCREQ6MTFDRDM5OTo2QTU3OTNFNiIsInZpc2l0b3JfaWQiOiI0MjU2NjcyODYyNTY2ODQ3NDYyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac4e222f6983fde40aee1983aea2fb552ed6e2f021800c9ea4f3252a1e8eeee829
hovercard-subject-tagpull_request:227907227
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/10296/files
twitter:imagehttps://avatars.githubusercontent.com/u/350812?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/350812?s=400&v=4
og:image:altThis PR adds co-routine support to unittest by adding a new sub-class of unittest.TestCase named unittest.AsyncioTestCase. It extends unittest.TestCase by adding the following functionality: a ne...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
Nonea87fc68e9bdf22e1c7e48ac6a60b98882f4bb103314b3f26b3460c61fc5441ae
turbo-cache-controlno-preview
diff-viewunified
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 full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasea2198d0212ed703af207673eb4d0868d4f867a5b
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/10296/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F10296%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
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
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
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/enterprise/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%2Fpull%2F10296%2Ffiles
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%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/10296/files
Reloadhttps://github.com/python/cpython/pull/10296/files
Reloadhttps://github.com/python/cpython/pull/10296/files
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 35k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 73.8k 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.3k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security and quality 0 https://github.com/python/cpython/security
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 and quality https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
dave-shawleyhttps://github.com/dave-shawley
python:masterhttps://github.com/python/cpython/tree/master
dave-shawley:bpo-32971-async-test-runnerhttps://github.com/dave-shawley/cpython/tree/bpo-32971-async-test-runner
Conversation 14 https://github.com/python/cpython/pull/10296
Commits 12 https://github.com/python/cpython/pull/10296/commits
Checks 0 https://github.com/python/cpython/pull/10296/checks
Files changed https://github.com/python/cpython/pull/10296/files
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
bpo-32972: Add unittest.AsyncioTestCase https://github.com/python/cpython/pull/10296/files#top
Show all changes 12 commits https://github.com/python/cpython/pull/10296/files
564ada6 unittest.TestRunner: introduce _runTest method. dave-shawley Oct 15, 2018 https://github.com/python/cpython/pull/10296/commits/564ada67a52aa52f565e3b2c9585e15a02d9afdd
9a780c6 unittest: Refactor TestCase.debug. dave-shawley Oct 15, 2018 https://github.com/python/cpython/pull/10296/commits/9a780c663785f40bdb25cd7333d4edfdbf83c16e
60d3514 Add unittest.AsyncioTestCase. dave-shawley Oct 21, 2018 https://github.com/python/cpython/pull/10296/commits/60d35149d7d4e2b684ccfa90618cabad7c86df88
6fa2911 unittest: Introduce asyncSetUp/TearDown. dave-shawley Oct 24, 2018 https://github.com/python/cpython/pull/10296/commits/6fa2911a1ee6661fc6edbc5c33560292f8e31817
231aab5 unittest: Introduce TestCase._terminateTest. dave-shawley Oct 24, 2018 https://github.com/python/cpython/pull/10296/commits/231aab56786b8af277898c0bb5a34ba6e155ade5
88a697c unittest: Shutdown async generators. dave-shawley Oct 25, 2018 https://github.com/python/cpython/pull/10296/commits/88a697cd022510f222e82ea64f0b7751da18c2a7
9f6263e unittest: Enable event loop debug flag. dave-shawley Oct 25, 2018 https://github.com/python/cpython/pull/10296/commits/9f6263e46a1dac1d77ed9280413604b41ca03946
694e6d5 bpo-32972: Switch to "newer style" classes. dave-shawley Nov 4, 2018 https://github.com/python/cpython/pull/10296/commits/694e6d544f3da09aea4026e9951ce49cf3bc6770
adb4c96 bpo-32972: Docstring cleanup in unittest.case. dave-shawley Nov 4, 2018 https://github.com/python/cpython/pull/10296/commits/adb4c96c6c3f948e59bc663f94a13e3831dcdc71
3c0ac43 bpo-32972: Rename AsyncioTestCase.event_loop. dave-shawley Nov 4, 2018 https://github.com/python/cpython/pull/10296/commits/3c0ac4307db6253d84542e52daea48da079547b6
7eb7899 bpo-32972: Add NEWS blurb. dave-shawley Nov 4, 2018 https://github.com/python/cpython/pull/10296/commits/7eb7899fb74417c6c076921e81c475ee3609b5c3
eed94cf Merge branch 'master' into bpo-32971-async-test-runner dave-shawley Nov 13, 2018 https://github.com/python/cpython/pull/10296/commits/eed94cfeefc66fb1b90c0929d5df930d4af63468
Clear filters https://github.com/python/cpython/pull/10296/files
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
__init__.py https://github.com/python/cpython/pull/10296/files#diff-e278af08db15e97de9401e1860464084b8b0df53251127bc1189cd2458bf62d7
case.py https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
test_asyncio_test_case.py https://github.com/python/cpython/pull/10296/files#diff-2aae2076998a427cdddf002d6a24db266cb18d360187f2bb496607baaa0953f8
2018-11-04-08-01-54.bpo-32972.MLIb8q.rst https://github.com/python/cpython/pull/10296/files#diff-82ea205796d13c4e80a90cc6434b6adbc168828538d5e7b7c7aa28cbee996351
Lib/unittest/__init__.pyhttps://github.com/python/cpython/pull/10296/files#diff-e278af08db15e97de9401e1860464084b8b0df53251127bc1189cd2458bf62d7
View file https://github.com/dave-shawley/cpython/blob/eed94cfeefc66fb1b90c0929d5df930d4af63468/Lib/unittest/__init__.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/10296/{{ revealButtonHref }}
https://github.com/python/cpython/pull/10296/files#diff-e278af08db15e97de9401e1860464084b8b0df53251127bc1189cd2458bf62d7
https://github.com/python/cpython/pull/10296/files#diff-e278af08db15e97de9401e1860464084b8b0df53251127bc1189cd2458bf62d7
https://github.com/python/cpython/pull/10296/files#diff-e278af08db15e97de9401e1860464084b8b0df53251127bc1189cd2458bf62d7
Lib/unittest/case.pyhttps://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
View file https://github.com/dave-shawley/cpython/blob/eed94cfeefc66fb1b90c0929d5df930d4af63468/Lib/unittest/case.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/10296/{{ revealButtonHref }}
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
https://github.com/python/cpython/pull/10296/files#diff-c6fe1ffe930def48a6adf1fa99b974737bac586fdacccacd1474e7b2f11370eb
PetterShttps://github.com/PetterS
Nov 13, 2018https://github.com/python/cpython/pull/10296/files#r233025992
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
dave-shawleyhttps://github.com/dave-shawley
Nov 15, 2018https://github.com/python/cpython/pull/10296/files#r233808232
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
Please reload this pagehttps://github.com/python/cpython/pull/10296/files
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.