[TIP] dynamically create tests with unittest
Albert-Jan Roskam
fomcl at yahoo.com
Wed Feb 25 14:19:14 PST 2015
Hi,
With nose one can use generators to dynamically create tests:
param_list = [('a', 'a'), ('a', 'b'), ('b', 'b')]
def test_generator():
for params in param_list:
yield check_em, params[0], params[1]
def check_em(a, b):
assert a == b
This could hardly be more elegant. What is the preferred way to do this with unittest? I have seen a few solutions, e.g.:
http://stackoverflow.com/questions/2798956/python-unittest-generate-multiple-tests-programmatically/2799009#2799009
Regards,
Albert-Jan
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
More information about the testing-in-python
mailing list