How can I run the same test against a lot of different data?
I want to be reported of all failures.
For example:
def isEven(number):
return True # Quite buggy implementation
data = [
(2, True),
(3, False),
(4, True),
(5, False),
]
class MyTest:
def evenTest(self, num, expected):
self.assertEquals(expected, isEven(num))
I have found solution which raises error on first failure only:
PHPUnit style dataProvider in Python unit test
How can I run a test to be reported of all failures?
You should be using
py.test. I think the unittest module was blindly copied from JUnit. Anyway, you can hack your way like this:And the output is:
Using this approach, you can add more niceties like printing debugging information on failure, etc.