How to specify test timeout for python unittest?

As far as I know unittest does not contain any support for tests timeout. You can try timeout-decorator library from PyPI. Apply the decorator on individual tests to make them terminate if they take too long: import timeout_decorator class TestCaseWithTimeouts(unittest.TestCase): # … whatever … @timeout_decorator.timeout(LOCAL_TIMEOUT) def test_that_can_take_too_long(self): sleep(float(‘inf’)) # … whatever else … To create … Read more

Timeout in async/await

You can use Promise.race to make a timeout: Promise.race([ doSomethingInSeries(), new Promise((_, reject) => setTimeout(() => reject(new Error(‘timeout’)), 11.5e3)) ]).catch(function(err) { // errors in res1, res2, res3 and the timeout will be caught here }) You cannot use setTimeout without wrapping it in a promise.