This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unittest: Automatically run coroutines in a loop
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: duplicate
Dependencies: Superseder: unittest.TestCase coroutine support
View: 32972
Assigned To: Nosy List: Petter S, yselivanov
Priority: normal Keywords: patch

Created on 2018-03-04 12:39 by Petter S, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6005 closed Petter S, 2018-03-06 17:38
Messages (3)
msg313211 - (view) Author: Petter S (Petter S) * Date: 2018-03-04 12:39
I am wondering whether it would be useful for unittest.TestCase to automatically run test methods that are coroutines within the default asyncio loop.

Example:

	class TestAsync(unittest.TestCase):

		async def test_foo(self):
			result = await foo()
			self.assertEqual(result, 42)

the test runner would then run test_foo within the default loop. If needed, we could also add functionality for providing a loop other than the default to the test class.

It seems to me that this functionality would be pretty easy to add to Lib/unittest/case.py:615 .

Personally, I think it would be useful. Right now I have to append every test case with a personal @run_in_loop decorator and I think unittest.TestCase could do this for me without breaking anything.
msg313344 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-03-06 17:58
I think the right approach would be to add an new base TestCase class: AsyncioTestCase.

And you should use the `asyncio.run` function to run the coroutine.
msg313346 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2018-03-06 18:03
This is a duplicate of issue 32972. Let's move the discussion there.
History
Date User Action Args
2022-04-11 14:58:58adminsetgithub: 77173
2018-03-06 18:03:41yselivanovsetstatus: open -> closed
resolution: duplicate
messages: + msg313346

superseder: unittest.TestCase coroutine support
stage: patch review -> resolved
2018-03-06 17:58:25yselivanovsetnosy: + yselivanov
messages: + msg313344
2018-03-06 17:38:47Petter Ssetkeywords: + patch
stage: patch review
pull_requests: + pull_request5770
2018-03-04 12:39:16Petter Screate