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?
Pandas drop_duplicates() method helps in removing duplicates from the Pandas Dataframe In Python.
Pandas DataFrame duplicated() Method The duplicated() method returns a Series with True and False values that describe which rows in the DataFrame are duplicated and not. Use the subset parameter to specify if any columns should not be considered when looking for duplicates.
Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
If you are using pytest you can go this way:
import pytest
def is_even(number):
return True # Wuite buggy implementation
@pytest.mark.parametrize("number, expected", [
(2, True),
(3, False),
(4, True),
(5, False)
])
def test_is_even(number, expected):
assert is_even(number) == expected
You will get something like (shortened):
/tmp/test_it.py:13: AssertionError
=========== 2 failed, 2 passed in 0.01 seconds ====================
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