{"id":24427,"library":"pytest-flask-sqlalchemy","title":"pytest-flask-sqlalchemy","description":"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.","status":"active","version":"1.1.0","language":"python","source_language":"en","source_url":"https://github.com/jeancochrane/pytest-flask-sqlalchemy","tags":["pytest","flask","sqlalchemy","testing","plugin"],"install":[{"cmd":"pip install pytest-flask-sqlalchemy","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Main plugin module; no common wrong import.","wrong":"","symbol":"pytest_flask_sqlalchemy","correct":"import pytest_flask_sqlalchemy"}],"quickstart":{"code":"import pytest\n\n@pytest.fixture\ndef app():\n    from myapp import create_app\n    app = create_app()\n    app.config['TESTING'] = True\n    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///:memory:'\n    return app\n\n@pytest.fixture\ndef db(app):\n    from myapp import db\n    db.init_app(app)\n    with app.app_context():\n        db.create_all()\n    yield db\n    db.drop_all()\n\ndef test_something(db):\n    # db.session is managed by plugin\n    assert True","lang":"python","description":"Basic setup with custom app and db fixtures; plugin ensures transaction rollback after each test."},"warnings":[{"fix":"Update dependencies: pip install --upgrade flask-sqlalchemy sqlalchemy","message":"Requires Flask-SQLAlchemy >=2.5 and SQLAlchemy >=1.3; incompatible with SQLAlchemy <1.3 and Flask-SQLAlchemy <2.5.","severity":"breaking","affected_versions":"1.0.0-1.1.0"},{"fix":"Use Python 3.7 or later.","message":"Drop of Python 3.6 support in v1.1.0. Python 3.7+ required.","severity":"breaking","affected_versions":">=1.1.0"},{"fix":"Upgrade pytest to >=6.0.1.","message":"pytest <6.0.1 is no longer supported as of v1.1.0.","severity":"deprecated","affected_versions":">=1.1.0"},{"fix":"Use db.session.rollback() or rely on plugin auto-rollback. Avoid explicit commit in tests.","message":"The plugin uses a transaction boundary per test; do not manually call db.session.commit() without rolling back, else test isolation may break.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use 'import pytest_flask_sqlalchemy' (the module itself provides fixtures).","cause":"Incorrect import path. Some users try to import from a submodule that doesn't exist.","error":"ImportError: cannot import name 'pytest_flask_sqlalchemy' from 'pytest_flask_sqlalchemy'"},{"fix":"Remove @pytest.mark.flask_sqlalchemy from tests; plugin works implicitly via conftest.","cause":"Plugin does not provide a mark; users mistakenly use a mark that doesn't exist.","error":"pytest.PytestUnknownMarkWarning: Unknown pytest.mark.flask_sqlalchemy - is this a typo?"},{"fix":"Fixtures are automatically available (e.g., 'db_session'), no need to import them explicitly.","cause":"Trying to access a non-existent class or fixture directly.","error":"AttributeError: module 'pytest_flask_sqlalchemy' has no attribute 'Fixtures'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}