In the third week we will review what we learned about testing and pytest in the previous weeks,
and we will introduce the concept of fixtures in pytest.
Let's start from reading more about the testing and pytest to review and expand what we learned in the previous weeks:
- Real Python: Effective Python thesting with pytest
- read the content of What makes pytest so useful
for a great overview of the reasons why
pytestis so popular - read the content of Parametrization: combining test to review the concept of parametrization
- read the content of What makes pytest so useful
for a great overview of the reasons why
- Real Python: Getting started with testing in Python
- you can read or just skim through the content of first 2 sections in order to see the difference between
unittestandpytest
- you can read or just skim through the content of first 2 sections in order to see the difference between
Fixtures are a powerful feature of pytest that allows you to define a set of data that you can reuse across multiple tests.
Fixtures are especially useful when you need to set up some data before running a test and clean up after the test is done.
You should read more from Real Python: Effective Python thesting with pytest to learn more about fixtures.
In the week3 branch you will find a new directory week3 that will be used as a working directory for this week.
The file week3/personal_info.py contains functions to extract important information from the dictionary with personal information.
- Create a new file
week3/test_personal_info.pyand write a test for the functionget_address - Create a ficture
personal_infothat can be used in the test file
- create a new file
week3/conftest.pyand define a fixturepersonal_info - modify the test to use the fixture
- Create a new test for the function
get_namethat will use the same fixture - Think if you could parametrize the fixture to test multiple cases
Last time we learned about parametrization of the testing functions when using pytest.
You can also parametrize fixtures to test multiple cases.
- read more about parametrizing fixtures in the
pytestdocumentation
Use the mark.parametrize to parametrize the fixture personal_info from the Exercise 1.
todo: setup and finalizer (file from cvs), tmpdir
Important
Update the repository in order to move to the next week/part of the course:
- After finishing all the exercises, create a Pull Request from the
week3branch to themainbranch - Check the status of tests
- If all tests pass, merge the Pull Request, this should update a new
README.mdon the main page of the repository (you can reload the page after 30-60s if you don't see the new content)
Get help: Submit an issue
Work was founded by BSSw Fellowship Program