Registry / testing / django-fake-model

django-fake-model

JSON →
library0.1.4pypypi✓ verified 25d ago

django-fake-model is a simple Python library designed for creating temporary, in-memory Django models specifically for unit testing purposes. It allows developers to quickly define and use fake models within their tests without polluting the main database schema, facilitating isolated and efficient testing. The current version is 0.1.4, and its release cadence has been very slow, with the last update in 2017.

pip install django-fake-model
INSTALL
IMPORT
SIG · DJANGO-FAKE-MODEL
D
django-fake-model
testingpythonv0.1.4
Install
1.5s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.1.4 · 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 · 17.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

model_me
✓ from django_fake_model import model_me
✗ from django_fake_model import model_me

This quickstart demonstrates how to use the `model_me` decorator to create a temporary Django model for a specific test method. The fake model is automatically registered and unregistered, ensuring test isolation. This code snippet should be placed within a Django test file and run as part of a Django test suite.

import unittest from django.test import TestCase from django.db import models from fake_model import model_me class MyFakeModelTest(TestCase): """ Example demonstrating the model_me decorator for creating a temporary Django model. To execute this test, ensure you have a Django project configured and run it via `python manage.py test your_app_name`. """ @model_me('my_app', 'MyFakeModel', fields={ 'name': models.CharField(max_length=255), 'value': models.IntegerField(default=0), }) def test_create_and_query_fake_model(self, MyFakeModel): # MyFakeModel is a temporary model class, available only within this test method self.assertFalse(MyFakeModel.objects.exists()) # Should be empty initially instance = MyFakeModel.objects.create(name='Test Item', value=42) self.assertEqual(instance.name, 'Test Item') self.assertEqual(instance.value, 42) retrieved = MyFakeModel.objects.get(name='Test Item') self.assertEqual(retrieved.pk, instance.pk) self.assertEqual(retrieved.value, 42) self.assertEqual(MyFakeModel.objects.count(), 1)
Debug
Known issues
breakingThe library has not been updated since 2017 and is likely incompatible with modern Django versions (3.x, 4.x, 5.x) and newer Python versions (3.8+). It was last officially tested with Django 1.9.
fix
For newer Django projects, consider using more actively maintained alternatives like `django-dynamic-models` or manual test-model creation. If absolutely necessary, pin Django to 1.9 and Python to 3.7 or earlier.
affects: All versions (0.1.x) when used with Django > 1.9 or Python > 3.7
gotchaThe lack of active maintenance since 2017 means the library may have unpatched bugs, security vulnerabilities, or simply not function as expected with contemporary Django ecosystem components.
fix
Carefully evaluate the long-term implications of using an unmaintained library. For new development, prioritize actively supported tools.
affects: All versions (0.1.x)
gotchaPrior to version 0.1.3, defining and using multiple fake models within the same test context could lead to unexpected behavior or conflicts. This was fixed in 0.1.3.
fix
Ensure you are using version 0.1.3 or higher to reliably use multiple fake models within your tests.
affects: <0.1.3
gotchaVersion 0.1.4 specifically fixed issues related to the `fake_me` class decorator when used with `nose` tests. If you are using `fake_me` with other test runners, thoroughly test its behavior.
fix
Upgrade to version 0.1.4 for `nose` compatibility. For other test runners (e.g., `pytest-django`), verify functionality explicitly or consider using `model_me` which might be more robust across different setups.
affects: <0.1.4, potentially 0.1.4 with non-nose runners
Upgrade
Version history
0.1.4latest on PyPI · released Feb 8, 2016
Audit
Dependencies
DjangorequiredCore dependency for functionality; designed to be used exclusively within Django projects.
Agent activity
13 hits · last 30 days
node
12
Resources
django-fake-model — pip install django-fake-model · libregistry