Message313451
> That code does not seem to work for me:
> https://gist.github.com/PetterS/f684095a09fd1d8164a4d8b28ce3932d
> I get "RuntimeWarning: coroutine 'test_async_with_mock' was never awaited"
> @mock.patch needs to work correctly for test methods.
> [..]
> No, unittest.TestCase can handle this, as demonstrated by two PRs in this bug. This would not change the behavior of existing (working) code.
Correct, and while it's possible to fix my little helper to work with mocks, you're completely right that we can, indeed, implement async support in TestCase without a metaclass. My mistake here, thanks for correcting!
In any case, while I think we can now talk about augmenting TestCase, I'd still want to first discuss few other issues:
1. Do we need support for async versions of setUp, setUpClass, etc? In my opinion: yes.
2. There're a few options how to implement (1):
a) Add async support to TestCase. Automatically detect when a test is async, or when 'setUp' and friends are async and run them all with 'asyncio.run'.
b) Add async support to TestCase. Add asyncSetUp, asyncSetUpClass, etc magic methods. The argument in favour of this approach over (a) is that it's possible to safely use 'super()' calls when you have multiply inherited TestCases.
c) Add a new AsyncioTestCase specifically for working with asyncio (combine with option (b)).
I still don't like (a) because it involves too much implicit logic. I think that it's simple enough to inherit your testcase from unittest.AsyncioTestCase and read a separate documentation specifically about it and not about generic TestCase. |
|
Date |
User |
Action |
Args |
2018-03-08 17:40:35 | yselivanov | set | recipients:
+ yselivanov, r.david.murray, njs, asvetlov, zach.ware, pdxjohnny, Petter S |
2018-03-08 17:40:35 | yselivanov | set | messageid: <1520530835.19.0.467229070634.issue32972@psf.upfronthosting.co.za> |
2018-03-08 17:40:35 | yselivanov | link | issue32972 messages |
2018-03-08 17:40:35 | yselivanov | create | |
|