Pytest database not creating tables

This page summarizes the projects mentioned and recommended in the original post on /r/flask

Scout Monitoring - Free Django app performance insights with Scout Monitoring
Get Scout setup in minutes, and let us sweat the small stuff. A couple lines in settings.py is all you need to start monitoring your apps. Sign up for our free tier today.
www.scoutapm.com
featured
InfluxDB - Power Real-Time Data Analytics at Scale
Get real-time insights from all types of time series data with InfluxDB. Ingest, query, and analyze billions of data points in real-time with unbounded cardinality.
www.influxdata.com
featured
  • pytest-flask-sqlalchemy

    A pytest plugin for preserving test isolation in Flask-SQLAlchemy using database transactions.

  • import flask import pytest import responses import werkzeug from myproject.app import create_app from myproject.ext import db class TestClient(flask.testing.FlaskClient): def __init__(self, *args, user=None, auth_token=None, **kwargs): self.user = user self.auth_token = auth_token super().__init__(*args, **kwargs) def open(self, *args, **kwargs): headers = kwargs.pop("headers", werkzeug.datastructures.Headers()) headers.extend({"Authorization": f"Bearer {self.auth_token}"}) kwargs["headers"] = headers return super().open(*args, **kwargs) test_app = create_app(conf="test") test_app.test_client_class = TestClient @pytest.fixture(scope="session", autouse=True) def app(): with test_app.app_context(): yield test_app @pytest.fixture(scope="session", autouse=True) def _db(app): import myproject.libs.mock_data db.create_all() myproject.libs.mock_data.load_data() yield db db.session.close() db.drop_all() @pytest.fixture(scope="function", autouse=True) def enable_transactional_tests(db_session): """ Ensure every test case is wrapped in a database transaction, that is rollbacked automatically. https://github.com/jeancochrane/pytest-flask-sqlalchemy#enabling-transactions-without-fixtures """ pass @pytest.fixture(scope="function", autouse=True) def create_responses(app): """ Ensure responses is always turned on for all test cases, so that if a test case forgets to mock something, it will be caught, and responses will raise a ConnectionError. """ ENABLE_RESPONSES = app.config["ENABLE_RESPONSES"] if ENABLE_RESPONSES: responses.start() yield responses.stop() responses.reset() else: yield @pytest.fixture(scope="session") def client(app): with app.test_client() as client: yield client

  • Scout Monitoring

    Free Django app performance insights with Scout Monitoring. Get Scout setup in minutes, and let us sweat the small stuff. A couple lines in settings.py is all you need to start monitoring your apps. Sign up for our free tier today.

    Scout Monitoring logo
  • flask_for_startups

    Flask boilerplate using a services oriented structure

  • Here's my conftest setup for reference (repo here:

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Why use marshmallow with REST API and ORM?

    1 project | /r/flask | 12 Dec 2022
  • ML web app

    1 project | /r/flask | 6 Aug 2022
  • In what cases do you apply decorators to Route Functions?

    1 project | /r/flask | 23 Jul 2022
  • Voting webapp saves votes locally, but not on server

    2 projects | /r/flask | 8 Jul 2023
  • replit discord.py why does line 6 print false?? logging in seems ok but bot doesn't respond

    1 project | /r/discordbots | 1 Jun 2023