I am new to Python and trying to do something I do often in Ruby. Namely, iterating over a set of indices, using them as argument to function and comparing its results with an a
In python world two most popular options to write tests are:
In pytest you parametrize tests very easly:
@pytest.mark.parametrize(('param1', 'param2'),[
(1, 'go'),
(2, 'do not go')])
def test_me(param1, param2):
# write test
This will produce nice output also while running tests:
go.py:2: test_me[1-go] PASSED
go.py:2: test_me[2-do not go] PASSED
I am using pytest for two years now and it's very nice tool. You have many features there. Besides parametrization there are fixtures also, very very nice assertions (you do not need to write assertEqual, just assert a==b
and pytest can generate very nice and helpful output for it.)