django-mock-queries
A django library for mocking queryset functions in memory for testing
Decision gist · record as of 2026-08-14
Yes. This is a mature, actively maintained testing utility with no dependencies, permissive licensing, and clear use cases for accelerating Django unit tests. Install it if you want to test query logic without database overhead; skip it only if your test suite already has fast database fixtures or you need QuerySet methods not yet supported (annotate, reverse, none, extra, raw, bulk_create, in_bulk, as_manager).AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction install with no runtime dependencies.
- Actively maintained with recent commits and stable production status since 2016.
License · maintenance · safety
MIT (permissive) — MIT license permits free use, modification, and distribution with minimal restrictions—suitable for commercial and open-source projects.
last release 2024-09-26 (687 days) · last repo commit 2026-04-14 · 324 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 204,780 downloads/mo, #9,601 on PyPI
Alternatives
Verify before relying
pip install django-mock-queries
from django_mock_queries.query import MockSet, MockModel
qs = MockSet(
MockModel(mock_name='john', email='john@gmail.com'),
MockModel(mock_name='bill', email='bill@gmail.com'),
)
result = [x for x in qs.all().filter(email__icontains='gmail.com')]- Whether all QuerySet methods used in production code are supported (TODO lists annotate, reverse, none, extra, raw, bulk_create, in_bulk, as_manager)
- Performance characteristics when mocking large datasets in memory
What it is and what it does
django-mock-queries lets you test Django code that queries models without setting up a database. It provides in-memory MockSet and MockModel classes that mimic Django's QuerySet API, supporting method chaining, filtering with Q objects, aggregates, field lookups, and CRUD operations. This is useful when you want fast unit tests that don't require database setup or migrations.
The library is typically used by patching Django model managers in test cases, allowing you to verify query logic in isolation. It also includes utilities for testing django-rest-framework serializers and can be configured to run an entire test suite without a database by monkey-patching the test database backend, which can significantly speed up test execution for projects with many migrations.
Use it for
- Unit test Django view logic that queries models without setting up a test database
- Mock User.objects or other model managers in test patches to verify filter and query logic
- Test django-rest-framework serializers with mocked model instances and nested serializers
- Speed up test suites by running tests without database setup when database-free testing is feasible
- Verify QuerySet method chaining and complex filter combinations with Q objects in isolation
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
This is a mature, actively maintained testing utility with no dependencies, permissive licensing, and clear use cases for accelerating Django unit tests. Install it if you want to test query logic without database overhead; skip it only if your test suite already has fast database fixtures or you need QuerySet methods not yet supported (annotate, reverse, none, extra, raw, bulk_create, in_bulk, as_manager).
Install
django-mock-queries on PyPI
Before you install
Low friction install with no runtime dependencies. Actively maintained with recent commits and stable production status since 2016.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions—suitable for commercial and open-source projects.
Quickstart
pip install django-mock-queries
from django_mock_queries.query import MockSet, MockModel
qs = MockSet(
MockModel(mock_name='john', email='john@gmail.com'),
MockModel(mock_name='bill', email='bill@gmail.com'),
)
result = [x for x in qs.all().filter(email__icontains='gmail.com')]
Verify before relying
- Whether all QuerySet methods used in production code are supported (TODO lists annotate, reverse, none, extra, raw, bulk_create, in_bulk, as_manager)
- Performance characteristics when mocking large datasets in memory
Package facts
| License | MIT permissive |
| Python support | Not specified |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 687 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 204,780 / month, #9,601 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3 :: OnlyTopic :: Software Development :: TestingTopic :: Software Development :: Testing :: MockingTopic :: Software Development :: Testing :: Unit |
Evidence: django_mock_queries-2.3.0-py2.py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “django queryset mocking”
- django-mock-queriesMocks Django QuerySet operations in memory for unit testing,…
- django-queryset-csvExports Django QuerySet data to CSV format with automatic…
- django-chunkatorIterates over large Django QuerySets in configurable chunks to avoid…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also mock-alchemy · djangorestframework-bulk · django-query-builder · django-cacheops · django-zen-queries · djangorestframework-filters · django-user-sessions · alchemy-mock · django-chunkator · django-sql-utils