Reputation: 1
class LoginTests(unittest.TestCase):
def setUp(self):
self.driver = Driver()
self.driver.browser.get(basic_url)
def test_add_user_uk(self):
LoginPage(self.driver).login(username, password)
AddUserPage(self.driver).test_add_user(return_uk_dict())
def tearDown(self):
self.driver.browser.quit()
if __name__ == '__main__':
unittest.main()
I'd like to run test_add_user_uk multiple times. Is it possible to make it in a loop?
Upvotes: 0
Views: 1639
Reputation: 2015
I may be wrong, but if you loop the test 'test_add_user_uk', the setUp and tearDown methods will not execute with the test after first iteration
you can try the unittest.TestSuite to achieve this
if __name__ == '__main__':
def suite(num):
suite = unittest.TestSuite()
for i in range(num):
suite.addTest(LoginTests('test_add_user_uk'))
return suite
runner = unittest.TextTestRunner()
runner.run(suite(3))
Having said that, if you can use pytest, the repeat functionaity can be easily achieved
https://docs.pytest.org/en/latest/
And you can use the following plugin to run the tests many times
https://pypi.org/project/pytest-repeat/
Upvotes: 2