Skip to main content

A variant on django.test.TestCase optimized for postgres

Project description

This is an alternate TestCase class to improve test running times (I measured a 2x improvement on some of my projects).

You can just use it and get a speed improvement for free, as long as your projects satisfy the follwoing conditions:

  • You use Django 1.3 (It might work with newer versions but I haven’t tried)

  • Your tests use postgreSQL as a database backend, 8.0 or newer

  • Your tests usa a single-database setup

  • Your tests don’t make operations on the db connection that make some state change that is not reverted by a savepoint rollback.

If the last point is false for a few of your tests, you can use the regular django.test.TestCase for that case, and gain the speed improvement in most of them.

How to use

Change your:

from django.test import TestCase

to:

from django_fasttest import TestCase

How does it work

What makes it faster is that fixture parsing/loading is done once per TestCase instead of once per test. Between tests in a same TestCase, the database is rolled back (using a pgsql savepoint) to the point just after loading the fixtures.

All the tests within a testcase use the same database connection (the standard TestCase class shuts down the connection between tests), and are run within the same transaction. If you use transactions in your code, you’ll have the same limitations as you do currently in Django 1.3

The speed benefits will be more noticeable if you have many test cases that use large fixtures, and if those tests are grouped in a TestCase.

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-fasttest-0.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file django-fasttest-0.1.tar.gz.

File metadata

File hashes

Hashes for django-fasttest-0.1.tar.gz
Algorithm Hash digest
SHA256 d7869d943968941c6947f93ab2bc3d23315e9dc5b63775077e19b78c7f77a373
MD5 68ed22c9ec561aab9fe6c05bb07439bd
BLAKE2b-256 8b4e5f3e04e21ef91755f01f05b07b5a37d2a5d3b42d81a6b6068e9d7a238a09

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page