alchemy-mock
SQLAlchemy mock helpers.
What it is and what it does
alchemy-mock provides utilities to mock SQLAlchemy sessions and query expressions in unit tests, eliminating the need to access a real database during testing. It includes ExpressionMatcher for comparing SQLAlchemy binary expressions (which normally produce another expression rather than a boolean), AlchemyMagicMock for basic session mocking, and UnifiedAlchemyMagicMock for more complex scenarios where sessions are queried multiple times with different filters. The library can stub real data by filtering criteria and partially supports session mutations like add() and add_all().
The package depends on six, sqlalchemy, and setuptools. It is classified as Pre-Alpha and has not been maintained since early 2021, with the last release in November 2019. While it has modest popularity, the abandoned status means bug fixes and compatibility updates are unlikely.
Use it for:
- Unit test SQLAlchemy-based code without spinning up a test database or fixtures.
- Assert that query filters were applied correctly by comparing filter expressions directly.
- Stub query results based on specific filter criteria to test conditional logic in data access layers.
- Mock session.add() and session.query() calls to verify ORM operations without persistence.
- Test complex multi-filter query chains by unifying and inspecting all filter calls together.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides mock helpers for SQLAlchemy sessions and expression matchers to enable unit testing without database access while preserving assertion capabilities.
Yes, but with caution. The package solves a real testing problem and has low install friction, but it is abandoned and has not been updated since 2021. Install it only if your SQLAlchemy and Python versions are compatible with its last release, and only if you are willing to maintain a fork or workaround if compatibility breaks. For new projects, consider actively maintained alternatives.
Install
alchemy-mock on PyPI
pip
pip install alchemy-mockuv
uv add alchemy-mockpoetry
poetry add alchemy-mockInstalling alchemy-mock
Before you install
Low install friction with three lightweight runtime dependencies. However, the package is abandoned—last release was 2019-11-05 and last commit 2021-01-07. No active maintenance means compatibility issues with newer SQLAlchemy or Python versions are unlikely to be addressed.
License in practice
MIT license is permissive and poses no restrictions on use, modification, or distribution in commercial or private projects.
Quickstart
pip install alchemy-mock
from alchemy_mock.mocking import UnifiedAlchemyMagicMock
session = UnifiedAlchemyMagicMock()
m = session.query(Model)
q = m.filter(Model.foo == 5)
data = q.all()
Requires SQLAlchemy to be installed; package is abandoned and may have compatibility issues with modern SQLAlchemy or Python versions.
Verify before relying
- Compatibility with SQLAlchemy versions released after 2021-01-07 is not documented.
- Whether the package works with Python versions beyond 3.6 is unclear given the abandoned status.
- Current real-world usage patterns and whether the package remains functional with modern dependencies.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — six, sqlalchemy, setuptools |
| Maintenance | abandoned — 2,474 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 223,061/month — #9,253 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: alchemy_mock-0.4.3-py2.py3-none-any.whl
Keywords: sqlalchemy, mock, testing
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
mock-alchemyProvides mock helpers for SQLAlchemy sessions…
permissive · top 15,000 on PyPI
django-mock-queriesMocks Django QuerySet operations in memory for…
permissive · top 15,000 on PyPI
sqlalchemy-mixinsProvides Active Record-style mixins for…
permissive · top 15,000 on PyPI
duckdb-engineA SQLAlchemy driver that enables you to use…
permissive · top 5,000 on PyPI
pytest-mock-resourcesProvides pytest fixtures that spin up real…
permissive · top 15,000 on PyPI
sqlalchemy-easy-softdeleteAdds soft-deletion support to SQLAlchemy models…
permissive · top 15,000 on PyPI
flexmockflexmock creates mock, stub, spy, and fake…
permissive · top 15,000 on PyPI
calleeProvides argument matchers for unittest.mock…
permissive · top 15,000 on PyPI
SQLAlchemy-ContinuumSQLAlchemy-Continuum adds automatic versioning…
permissive · top 5,000 on PyPI
sqlalchemy-filtersAdds filtering, sorting, and pagination…
permissive · top 15,000 on PyPI