Skip to content

Instantly share code, notes, and snippets.

@pgebert
Last active January 15, 2022 11:59
Show Gist options
  • Save pgebert/d6b21cb7b81562aaa1fdbfe3b4836dd8 to your computer and use it in GitHub Desktop.
Save pgebert/d6b21cb7b81562aaa1fdbfe3b4836dd8 to your computer and use it in GitHub Desktop.
Pytest fixture to test requests for flask applications.
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