Last active
January 15, 2022 11:59
-
-
Save pgebert/d6b21cb7b81562aaa1fdbfe3b4836dd8 to your computer and use it in GitHub Desktop.
Pytest fixture to test requests for flask applications.
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
from typing import Generator | |
import pytest | |
from flask import Flask | |
from ..app import create_app | |
/** | |
* Created by pgebert on 10/01/22. | |
* | |
* Pytest fixture to test requests for flask applications. | |
*/ | |
@pytest.fixture(scope="session") | |
def test_app() -> Generator[Flask, None, None]: | |
""" Fixture to provide a flask app instance | |
for testing. | |
Returns: | |
Flask: flask app | |
""" | |
app = create_app() | |
with app.app_context(): | |
app.testing = True | |
client = app.test_client() | |
yield client | |
/** | |
* Example usage in pytest | |
*/ | |
def test_put_records(test_app): | |
response = test_app.get(f"/items") | |
assert response.status_code == 200 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment