Skip to main content

Run Django tests with optimization options to decrease runtime while keeping them trustable

Project description

django-lightweight-tests

Run Django tests with optimization options to decrease runtime while keeping them trustable.

In our tests using SQL Server, a 30 minutes runtime was reduced by 90%.

Most of these ideas were based on the article 7 Ways to Speed Up Your Django Test Suite by Tobin Brown.

How it works

This package removes the following functionalities from Django, which greatly reduces tests runtime:

Migrations

Unless you test your migration files, there is no need to run all migrations everytime you run your test suite. So this option creates all necessary database structure without looking at your migration files.

Warnings

Supress warnings to reduce print statements and make your test output cleaner.

Password hasher

If your tests create a lot of users, it may be useful to use a simple password hasher.

Middlewares

Adds only necessary middlewares to the request object.

DEBUG = False

Decreases Django overhead when debugging is activated.

SQLite

Run tests using SQLite.

How to install

Add this line to your requirements.txt:

-e git+https://github.com/luisccf/django-lightweight-tests.git#egg=django-lightweight-tests

Then simply run

pip install -r requirements.txt

How to use

Add the following code to your manage.py:

import sys
from django_lightweight_tests import LightweightTest

...

is_testing = 'test' in sys.argv
if is_testing:
    LightweightTest()

...

execute_from_command_line(sys.argv)

How you check if you are running your tests depends on your test runner. We run our tests using python manage.py test, so this check works for us.

When you run your tests, pass the option --light:

python manage.py test --light

You can change the arg name when instantiating the class:

LightweightTest(cmd_option='--opt')
python manage.py test --opt

Project details


Download files

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

Source Distribution

django-lightweight-tests-0.0.1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_lightweight_tests-0.0.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file django-lightweight-tests-0.0.1.tar.gz.

File metadata

  • Download URL: django-lightweight-tests-0.0.1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

File hashes

Hashes for django-lightweight-tests-0.0.1.tar.gz
Algorithm Hash digest
SHA256 95e68dfc4e682181be588e11c7846ce5cd5edaccc46ebbaa71202d6e4feb232b
MD5 cffa901eafd1cb04c9fefa51a1fd5ce7
BLAKE2b-256 0c8d507ac094be902829f010b8ca69cb3592b0fa871c4e699617759eea6108ba

See more details on using hashes here.

File details

Details for the file django_lightweight_tests-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: django_lightweight_tests-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

File hashes

Hashes for django_lightweight_tests-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8a0be5551d462a3fceb2148ef72829b1ca3c0e549688e41e41efb05a06ed58db
MD5 6a742c2b0fb29e42855097ec5555aacd
BLAKE2b-256 db69df95a179745a021cfc35c5f06af3e1e3c75432ef70199291b096913b327e

See more details on using hashes here.

Supported by

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