Now that you have written four different positive 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 have seen pytest.mark.parametrize in the notes. Using the documentation of pytest.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 and expected, 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.
Commit your solution including Answers UCL-COMP0233-23-24/RSE-Classwork#21 in the message, and push it to GitHub.
What are the advantages and disadvantages of using parametrize in this case?
Now that you have written four different positive 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.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.Commit your solution including
Answers UCL-COMP0233-23-24/RSE-Classwork#21
in the message, and push it to GitHub.What are the advantages and disadvantages of using
parametrize
in this case?Sample solution