Skip to content

Examples of different testing methodologies with trivial examples, incorporating FastAPI and Redis

Notifications You must be signed in to change notification settings

KrupaH/pytest_examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Install dependencies

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)

Run the test suite

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

Check test coverage

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.

Run the application locally

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

About

Examples of different testing methodologies with trivial examples, incorporating FastAPI and Redis

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages