开发者

Python unit test. How to add some sleeping time between test cases?

I am using python unit test module. I am wondering is there anyway to add some delay between every 2 test cases? 开发者_Go百科Because my unit test is just making http request and I guess the server may block the frequent request from the same ip.


Put a sleep inside the tearDown method of your TestCase

import time

class ExampleTestCase(unittest.TestCase):
    def tearDown(self):
        time.sleep(1)  # sleep time in seconds

tearDown() will be executed after every test within that TestCase class.

The modules documentation can be found here.


import time
time.sleep(2.5) # sleeps for 2.5 seconds

You might want to consider making the delay a random value between x and y.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜