Skip to content

vinyasmusic/flask-testing-demo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Flask Testing Demo

A demo project to showcase Testing with a Flask app

Why ? What ? How ?

Getting Started

This is assuming you have Python and PostgreSQL already setup on your machine, if not then go here to learn how to do this.

  1. Clone the repo
  2. Install Poetry by following the instructions on their website
  3. Navigate to the root of the project and run:
$ poetry install

This will create a virtual environment and install all the dependencies listed in pyproject.toml.

  1. You can then activate the virtual environment by poetry shell
  2. Some environment variables might be needed to kickstart the app
export POSTGRES_PASSWORD=PASSWORD
export WEATHER_API_KEY=TEST
export FLASK_APP=run.py
export FLASK_ENV=testing
export FLASK_DEBUG=1
  1. Start the flask app by flask run

The app will be accessible at http://localhost:5000.

What is unit testing ?

  • Unit testing is a software testing technique that involves testing individual units or components of code in isolation from the rest of the system.
  • It focuses on testing the functionality of each unit in isolation, verifying that it produces the expected output for a given input or set of inputs.
  • It verifies different states or behavioral aspects of the application
  • Can be single function or single use-case (*)

Why is unit testing important?

  • Unit testing helps catch bugs and defects early in the development process, making them easier and less expensive to fix.
  • Ensures that the code is working as expected and meeting requirements.
  • Increases code quality, maintainability, and re-usability.
  • Faster and more frequent releases, reducing time to market and enhancing customer satisfaction.
  • Refactoring with confidence, ensuring that changes do not break existing functionality.

Why pytest ?

  • Pytest is a powerful, flexible, and comprehensive testing framework.
  • Simple and intuitive API that makes it easy to write and manage tests.
  • Support test fixtures and plugins that enable advanced testing features, such as parameterization, fixtures, and mocks.
  • Rich ecosystem of third-party plugins and extensions that enhance its functionality and enable integration with other tools and frameworks.
  • Clear and concise test reports that make it easy to understand the test results and identify issues quickly.
  • Community

Links

  1. Pytest Plugins
  2. Test Podcast
  3. Pytest Examples
  4. Python Debugging