I have an python unitest. In the setupClass method I so some timeconsuming tasks... The tests itself run very fast. Now i would like to run the same Testcase with multiple sets of parameters. How can I achieve this?
I ve tried differet approaches with nose_parameterized etc. but there i cant use the @parameterized.expand()
import unittest
from nose_parameterized import parameterized
parameters = [('test1', 2 ),('test2', 3)]
class TestParameterizedTestcase(unittest.TestCase):
@classmethod
def setUpClass(cls, param=1):
"""
Do some expensive stuff
"""
cls.param = param
print 'Param in setup class %s'
def test_is_one(self):
"""
A fast test
"""
self.assertEqual(1,self.param)
def test_is_two(self):
"""
Another fast test
"""
self.assertEqual(2, self.param)
def test_is_three(self):
"""
Another fast test
"""
self.assertEqual(3, self.param)
Unfortunately there isn't any way to create parameterized test classes with either
unittest
,nose
, orparameterized
.py.test
has an example showing how you can build your own parameterized test class, here: https://pytest.org/latest/example/parametrize.html#a-quick-port-of-testscenariosAnd you can build your own parameterized class generator like this:
Which will generate a new test class for each paramter.