Registry / testing / pytest-flask-sqlalchemy

pytest-flask-sqlalchemy

JSON →
library1.1.0pypypi✓ verified 88d ago

A pytest plugin that provides fixtures to preserve test isolation in Flask-SQLAlchemy by using database transactions. It simplifies testing Flask applications with SQLAlchemy by allowing tests to roll back changes automatically. Current version is 1.1.0, with a release cadence of irregular minor updates.

pip install pytest-flask-sqlalchemy
INSTALL
IMPORT
SIG · PYTEST-FLASK-SQLAL
P
pytest-flask-sqlalchemy
testingpythonv1.1.0
Install
5.4s avg
Import
—
Disk
60MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 60.6MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 5.4s · import 0.000s · 59MB
60MB installed
● package 60MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

pytest_flask_sqlalchemy
✓ import pytest_flask_sqlalchemy
Main plugin module; no common wrong import.

Basic setup with custom app and db fixtures; plugin ensures transaction rollback after each test.

import pytest @pytest.fixture def app(): from myapp import create_app app = create_app() app.config['TESTING'] = True app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:' return app @pytest.fixture def db(app): from myapp import db db.init_app(app) with app.app_context(): db.create_all() yield db db.drop_all() def test_something(db): # db.session is managed by plugin assert True
Debug
Known issues
breakingRequires Flask-SQLAlchemy >=2.5 and SQLAlchemy >=1.3; incompatible with SQLAlchemy <1.3 and Flask-SQLAlchemy <2.5.
fix
Update dependencies: pip install --upgrade flask-sqlalchemy sqlalchemy
affects: 1.0.0-1.1.0
breakingDrop of Python 3.6 support in v1.1.0. Python 3.7+ required.
fix
Use Python 3.7 or later.
affects: >=1.1.0
deprecatedpytest <6.0.1 is no longer supported as of v1.1.0.
fix
Upgrade pytest to >=6.0.1.
affects: >=1.1.0
gotchaThe plugin uses a transaction boundary per test; do not manually call db.session.commit() without rolling back, else test isolation may break.
fix
Use db.session.rollback() or rely on plugin auto-rollback. Avoid explicit commit in tests.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'pytest_flask_sqlalchemy' from 'pytest_flask_sqlalchemy'
Incorrect import path. Some users try to import from a submodule that doesn't exist.
fix
Use 'import pytest_flask_sqlalchemy' (the module itself provides fixtures).
pytest.PytestUnknownMarkWarning: Unknown pytest.mark.flask_sqlalchemy - is this a typo?
Plugin does not provide a mark; users mistakenly use a mark that doesn't exist.
fix
Remove @pytest.mark.flask_sqlalchemy from tests; plugin works implicitly via conftest.
AttributeError: module 'pytest_flask_sqlalchemy' has no attribute 'Fixtures'
Trying to access a non-existent class or fixture directly.
fix
Fixtures are automatically available (e.g., 'db_session'), no need to import them explicitly.
Upgrade
Version history
1.1.0latest on PyPI · released Apr 30, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
20 hits · last 30 days
node
16
Resources
pytest-flask-sqlalchemy — pip install pytest-flask-sqlalchemy · libregistry