Clone this repo to work on pytest hands-on. Associated blog post: https://krupahebbar.substack.com/p/pytest-with-python-from-beginner-to-expert-aeb1152c2981
The project contains a simple FastAPI app and a few helper methods, along with test cases for all of them.
Create a virtualenv and install from requirements.txt
python3 -m venv pytest_examples_venv
source pytest_examples_venv/bin/activate
pip install -r requirements.txt
(or use anaconda or any package manager of your choice with the given requirements.txt)
To run the test suite in verbose mode, run the following command from project root:
python -m pytest -vv .
Note: Running pytest as a python module handles some import-related issues that could come up
To check test coverage, run the following command from project root:
coverage run -m pytest .
coverage report # to display coverage summary
To create htmlcov/ folder with navigable html files to see details of coverage within each file, run
coverage html
and then open htmlcov/index.html in your browser.
Note: to run the actual fastapi server, you will need to have redis-server running on your system, and you can run this command from the repository root:
python -m app.server
The API docs page will then be visible at http://localhost:19999/docs