Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Created February 6, 2019 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/68bfceb92de95d509019daa1d0161534 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/68bfceb92de95d509019daa1d0161534 to your computer and use it in GitHub Desktop.
Pytest Fixture for Flask #python
import pytest
@pytest.fixture(scope='session')
def api_client(api_environment):
from YOURFLASKMODULE import app
# switch on testing mode to propagate exceptions from within the app
app.testing = True
# this is needed when testing to allow url_for URL generation
app.config['SERVER_NAME'] = 'localhost'
# push the app context to allow tests to access the flask.current_app singleton
ctx = app.app_context()
ctx.push()
yield app.test_client()
ctx.pop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment