Created
February 6, 2019 00:46
-
-
Save CMCDragonkai/68bfceb92de95d509019daa1d0161534 to your computer and use it in GitHub Desktop.
Pytest Fixture for Flask #python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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