I’m using Python’s unittest.
I’d like to write a test that ensures a certain method completes before a certain time. I can do this by the usual calculation of the difference between timestamp after and timestamp before, but I started wondering if
- is this commonly done in TDD, write tests that fail if a method / function is not efficient and then refactor to make it more efficient?
- does Python’s unittest have a slick way to do this?
You can do it with nose @timed decorator. I use it for testing functions with timing. Example: