This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 112
Avoid code repetition in the tests #89
Labels
Comments
twemyss
added a commit
to twemyss/rse-classwork-2020
that referenced
this issue
Nov 5, 2020
TomSwift1
added a commit
to TomSwift1/rse-classwork-2020
that referenced
this issue
Nov 5, 2020
Closed
premal-varsani
added a commit
to premal-varsani/rse-classwork-2020
that referenced
this issue
Nov 5, 2020
ucapgum
referenced
this issue
in ucapgum/rse-classwork-2020
Nov 5, 2020
aixixu
pushed a commit
to aixixu/rse-classwork-2020
that referenced
this issue
Nov 5, 2020
premal-varsani
added a commit
to premal-varsani/rse-classwork-2020
that referenced
this issue
Nov 5, 2020
nikoSchoinas
pushed a commit
to nikoSchoinas/rse-classwork-2020
that referenced
this issue
Nov 5, 2020
umitozmen
added a commit
to umitozmen/rse-classwork-2020
that referenced
this issue
Nov 6, 2020
Open
DavidScobie
referenced
this issue
in DavidScobie/rse-classwork-2020
Nov 16, 2020
rmapjs1
added a commit
to rmapjs1/rse-classwork-2020
that referenced
this issue
Dec 20, 2020
Answers Issue UCL-RITS#89
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Avoid code repetition using pytest.mark.parametrize
Now that you have written four different tests for
times.py
, take a step back and look at your code: There is a lot of repetition, almost every test (apart from the negative test) essentially does the same (albeit with different data), which makes our test code harder to change in the future. (You can start from the sample solution if you prefer.)We can use
pytest.mark.parametrize
to get our tests DRY (Don't Repeat Yourself).pytest.mark.parametrize
in the notes. Using the documentation ofpytest.mark.parametrize
if needed, see how you can compress most of the tests on a single one.You will need the test function to accept parameters, for example
time_range_1
,time_range_2
andexpected
,let the parametrize decorator know about it as its first argument and pass a list of tuples of length 3
with the values for each test.
What are the advantages and disadvantages of using
parametrize
in this case?If you are finished with this issue, feel free to continue working the related issue #92 , looking at test fixtures.
A sample solution for this exercise can be found here.
The text was updated successfully, but these errors were encountered: