Skip to content
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.

Avoid code repetition in the tests #89

Open
alessandrofelder opened this issue Nov 5, 2020 · 0 comments
Open

Avoid code repetition in the tests #89

alessandrofelder opened this issue Nov 5, 2020 · 0 comments
Labels

Comments

@alessandrofelder
Copy link
Collaborator

alessandrofelder commented Nov 5, 2020

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).

  • 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.

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.

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
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
rmapjs1 added a commit to rmapjs1/rse-classwork-2020 that referenced this issue Dec 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

1 participant