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.

Alex Coleman
  • 607
  • 1
  • 4
  • 11

1 Answers1

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])
Lior Cohen
  • 5,570
  • 2
  • 14
  • 30