I am new to Python and trying to do something I do often in Ruby. Namely, iterating over a set of indices, using them as argument to function and comparing its results with an array of fixture outputs.
So I wrote it up like I normally do in Ruby, but this resulted in just one test case.
def test_output(self): for i in range(1,11): .... self.assertEqual(fn(i),output[i])
I'm trying to get the test for every item in the range. How can I do that?
If they have not provided their environment to run test cases in a loop. And locally if You are running code for python compiler It would be useful. you can simply use a while loop or range function of python.
We can run multiple test cases using TestNG test suite in Selenium webdriver. To execute test cases simultaneously, we have to enable parallel execution in TestNG. A TestNG execution is driven by the TestNG xml file. To trigger parallel execution we have to use the attributes – parallel and thread-count.
Starting from python 3.4, you can do it like this:
def test_output(self): for i in range(1,11): with self.subTest(i=i): .... self.assertEqual(fn(i),output[i])
https://docs.python.org/3.4/library/unittest.html?highlight=subtest#distinguishing-test-iterations-using-subtests
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