- UnitTest Framework Tutorial
- UnitTest Framework - Home
- UnitTest Framework - Overview
- UnitTest Framework - Framework
- UnitTest Framework - API
- UnitTest Framework - Assertion
- UnitTest Framework - Test Discovery
- UnitTest Framework - Skip Test
- UnitTest Framework - Exceptions Test
- UnitTest Framework - Time Test
- UnitTest Framework - Unittest2
- UnitTest Framework - Signal Handling
- UnitTest Framework - Doctest
- UnitTest Framework - Doctest API
- UnitTest Framework - Py.test Module
- Nose Testing - Framework
- Nose Testing - Tools
- UnitTest Framework Resources
- UnitTest Framework - Quick Guide
- UnitTest Framework - Resources
- UnitTest Framework - Discussion
UnitTest Framework - Time Test
Junit, the Java unit testing framework (Pyunit is implementation of JUnit) has a handy option of timeout. If a test takes more than specified time, it will be marked as failed.
Python's testing framework doesn't contain any support for time out. However, a third part module called timeout-decorator can do the job.
Download and install the module from −
https://pypi.python.org/packages/source/t/timeout-decorator/timeout-decorator-0.3.2.tar.gz
- Import timeout_decorator in the code
- Put timeout decorator before the test
- @timeout_decorator.timeout(10)
If a test method below this line takes more than the timeout mentioned (10 mins) here, a TimeOutError will be raised. For example −
import time import timeout_decorator class timeoutTest(unittest.TestCase): @timeout_decorator.timeout(5) def testtimeout(self): print "Start" for i in range(1,10): time.sleep(1) print "%d seconds have passed" % i if __name__ == '__main__': unittest.main()
Advertisements