-
Notifications
You must be signed in to change notification settings - Fork 20
Exercise 2+ (parametrising your tests) #8
Description
pytest.mark.parametrize - Don't repeat yourself
Good practice in writing software is to avoid repetition in the code. A major reason for this is that if you want to make changes to the code in the future (e.g. we might want to add an argument to time_range like the timezone) you'd have to change this in several places in the code, which is more effort and increases the probability of forgetting to change one of the various places.
Most of the tests so far are very similar in structure. We can use pytest.mark.parametrize to get our tests DRY (Don't Repeat Yourself).
- Read the
pytest.mark.parametrizedocumentation and see how you can compress most of the tests so far into a single parametrised test.
You will need the test function to accept parameters, for example called test_input and expected,
let the parametrize decorator know about it as its first argument and pass a list of pairs
with the values for each test.
Once you've done this, commit your changes to your repository with a meaningful commit message that also links to this issue.
> git add test_times.py
> git commit -m "<meaningful commit message here>. Answers UCL-RITS/ipls-workshop#8"
and push it to your fork.
> git push