0

I want to apply the same unittest to different inputs and outputs. For instance:

def test_something(self):
   calculated = some_funtion(input_data[idx])
   self.assertEquals(calculated, expected[idx])

for all idx (say, 1,000).

There's this question that asks something similar, but the question does not have any satisfactory answers.

I have to use Python unittest.

1 Answer 1

1

If you must stick with unittest and not use the superior pytest, I would recomend to use the parameterized library.

from parameterized import parameterized

class MyTest(unittest.TestCase):
   @parameterized.expand([1,2,3,...., 100])  # your idxs
   def test_something(self, idx):
       calculated = some_funtion(input_data[idx])
       self.assertEquals(calculated, expected[idx])
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.