Closed wkCircle closed 12 months ago
Module tests/unit/parameterized.py
is implemented for this issue. We could leverage this module to write parameterized tests this way:
from tests.unit import parameterized
class ListTest(unittest.TestCase):
"""Unit test cases of interfact List."""
...
@parameterized.named_parameters(
dict(
testcase_name='case 1',
test_func=lambda e: e == 1,
expected_result=True),
dict(
testcase_name='case 2',
test_func=lambda e: e == 5,
expected_result=False),
dict(
testcase_name='case 3',
test_func=lambda e: e > 1,
expected_result=True),
)
def test_api_exists(self, testcase_name, test_func, expected_result):
"""Tests the method `exists` on FPU list."""
alist = fl(1, 2, 3)
self.assertEqual(
alist.exists(test_func), expected_result)
Sorry for the inconvenience in accidentally closing this issue. We still have some works to do from this issue. So I reopen it again.
No worries, guess we can close the issue now.
@pytest.mark.parameterize
doesn't support decorating functions inside unitttest.TestCase class with self/classmethod/staticmethod. Unfortunately, pytest has claimed that they won't fix such issue (see pytest issue 541).We need to find alternatives to replace
@pytest.mark.parameterize
functionality for testing.Besides, keep in mind the AAA structure as mentioned before by @johnklee .