Giter VIP home page Giter VIP logo

flask-pytest's Introduction

Flask-pytest

Current version on PyPI

Runs pytest in a background process when DEBUG is True.

Motivation

Running tests shouldn't be something you have to go out of your way to do. With this Flask extension, the tests will be automatically be run for you, and re-run when code changes.

Installation

$ pip install flask-pytest

Usage

Add app = FlaskPytest(app) to your project:

from flask import Flask
from flask.ext.pytest import FlaskPytest

app = Flask(__name__)
app.config.from_pyfile('settings.py')

app = FlaskPytest(app)  # <-- Add this line

@app.route('/')
def hello():
    return 'Hello World!'

app.run()
settings.py
DEBUG = True

Your tests will now be run in the background:

 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
 * Restarting with reloader
Running tests...
...
3 passed in 1.20 seconds

If a test fails, you'll hear a beep and see the output. Change a source file to reload the development server like normal, which will now re-run the tests.

Configuration

Flask-pytest runs out-of-the-box without any config. However, you may want to tweak the behavior here and there. Here's a list of available settings you can add to your app.config:

  • FLASK_PYTEST_ENABLED: Set to True to run tests regardless of DEBUG, or to False to disable the extension entirely. If None, the extension will run when DEBUG is True. Default: None

  • FLASK_PYTEST_BEEP: Beep when pytest returns a non-zero exit code. Default: True

  • FLASK_PYTEST_EXITFIRST: Stops running tests if a test fails. Default: True

  • FLASK_PYTEST_QUIET: Runs pytest in quiet mode. Default: True

Contributing

  1. Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found
  2. Fork the repository, make your changes, and add yourself to Authors.md
  3. Send a pull request

If your PR has been waiting a while, feel free to ping me on Twitter.

flask-pytest's People

Contributors

joeyespo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

flask-pytest's Issues

Use a subprocess instead of threads

Version 0.0.1 uses threads as a proof of concept. It works in simple cases, though it's more error-prone than a process.

I'm considering using multiprocessing because it's very clean. It'll also have to use a Queue to send pytest output back to the parent process.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.