I am using python unit test module. I am wondering is there anyway to add some delay between every 2 test cases? 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With