-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add the TestCase.with_timeout decorator. #61
base: master
Are you sure you want to change the base?
Conversation
@Martiusweb What do you think about the change? |
@Martiusweb What's the min version of Python you'd like to support in asynctest? |
Hi, currently the target is python 3.4 until its EOL (2019-03-16), but this may change if the support of this version becomes a problem with future changes in the language. |
@Martiusweb Perhaps the decorator should also support class as it's target (i.e. setting timeout for all coroutines). The implementation might be changed to set an attribute on a function / class instead and then letting AsyncTestCase to runt with timeout. |
@Martiusweb Any thoughts regarding that improvement? |
I'm not 100% convinced about a timeout feature. A general-purpose timeout decorator around a coroutine is out of the scope of asynctest (imho), and if we want to tie this to TestCase, there are a couple of concerns: Do we want a decorator for the whole class? A test function is not always a coroutine, should we support timeouts in this case? Do we want a default timeout value?
Implementation
the timeout would then be set when TestCase runs the test. What do you think? |
I agree with your comment regarding the general purpose timeout decorator. There is at least async_timeout (by aiohttp authors) for async code and timeout-decorator for sync code. We can introduce an optional feature via setuptools's extra with necessary dependencies.
Makes sense.
Not necessarily but I expect developers who use asyncio to find it convenient to restrict both async and sync functions (where latter are often implemented as blocking async functions internally).
I think that the most common usage of this feature will be to detect deadlocks within async code. Therefore I think it's convenient to have a sensible default value as well as to support the env variable to override that default. Implementation that I propose:
|
I really want to avoid dependencies if possible, especially when the library represents ~100-200 LOC. I think it's reasonable to only support asyncio timeouts and assume it's not our job to interrupt a non async test (this is more the job of the test runner).
I think my proposal is somewhat more convenient for this case: I'm not sure what would be a "sensible" default, and I don't think that an environment variable is the best way to override that default value: I prefer to use environment variable as a "global switch" that applies to everything that is run. That's why I proposed that the ASYNCTEST_TIMEOUT variable would apply to all (coroutine) tests, even if they're not decorated. |
Perhaps it makes sense to skip env vars initially and wait until someone else will request them. |
c2e9ce1
to
967481c
Compare
Like #43 but less generic.
This is a backport from @GreatFruitOmsk's internal async_unittest written by @amezin.