Skip to main content

This proxy database backend is designed to speed up multi-threaded testing setups.

It enables those setups (for instance using LiveServerTestCase) to use Django’s standard TestCase - where each test runs in its own transaction - instead of the much slower TransactionTestCase that needs to flush the whole database between each tests.

It is NOT intended for production use, only for faster testing setups.

This project support Django versions 1.6, and Python 2.7, 3.2 and 3.3.

Setup

First, install django-shareddb:

$ pip install django-shareddb

Then, simply update your settings to use its wrapping engine:

DATABASES = {
    'default': {
        'ENGINE': 'shareddb.backends.shareddb',
        'INNER_ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test-dbsharing',
    }
}

Since altering those settings is very frequent, django-shareddb also provides a simple patch_databases function:

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': 'test-dbsharing',
    }
}

if os.environ['FAST_TESTS']:
    import shareddb
    DATABASES = shareddb.patch_databases(DATABASES)

Once the settings are ready, simply replace your calls to Django’s LiveServerTestCase with the django-shareddb variant:

from shareddb import testcases

class MyTests(testcases.LiveServerTestCase):
    def test_something(self):
        # Your test here

The django-shareddb LiveServerTestCase is simply a clone of Django’s version, but uses django.test.TestCase instead of django.test.TransactionTestCase.

Testing

This libraries has been succesfully tested with sqlite and postgresql.

If you want to test it with other databases, please clone it and alter dev/settings.py for your setup, then run ./manage.py test.

Metadata

Release files for django-shareddb 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-shareddb 0.1.2
File Size Uploaded
django-shareddb-0.1.2.tar.gz 8.6 kB Details

Release files / django-shareddb-0.1.2.tar.gz

Download URL django-shareddb-0.1.2.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2417df2886dd45805faedb9e1052a0b5d5455876f44e652c97b1975de6ff819f
BLAKE2b-256 checksum
How to use checksums
92d793a3ccb2294fb15ed8e6277238a8dadb603757c6499636acff29e15e1213
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.2 This release

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page