0
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?

1
  • Can't you add a loop inside the function? You could for example use a counter inside a try-except block inside a for range loop, if you're going for a test based on percentage of succeeding. Commented Nov 27, 2018 at 12:26

1 Answer 1

2

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/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.