--- id: django-mock-queries version: "2.3.0" license: MIT license_treatment: permissive maintenance: active --- # django-mock-queries — A django library for mocking queryset functions in memory for testing License: permissive · Maintenance: active · Downloads: 204.8K/mo ## 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 above — verify before relying. Mocks Django QuerySet operations in memory for unit testing, supporting filtering, aggregation, field lookups, and CRUD operations without a database. 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 pip install django-mock-queries uv add django-mock-queries poetry add django-mock-queries ## Installing django-mock-queries 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: unspecified - Install friction: low - Maintenance: active - Downloads: 204.8K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django queryset mocking, in-memory django testing, mock django orm, django unit test fixtures, django query testing without database, mock django models, django test doubles, django-testing, unit-testing, mocking [View on SkillFed](https://skillfed.io/packages/django-mock-queries) · [View on PyPI](https://pypi.org/project/django-mock-queries/)