Runs pytest in a background process when DEBUG
is True
.
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.
$ pip install flask-pytest
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()
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.
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 toTrue
to run tests regardless ofDEBUG
, or toFalse
to disable the extension entirely. IfNone
, the extension will run whenDEBUG
isTrue
. 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
- Check the open issues or open a new issue to start a discussion around your feature idea or the bug you found
- Fork the repository, make your changes, and add yourself to Authors.md
- Send a pull request
If your PR has been waiting a while, feel free to ping me on Twitter.