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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-lightweight-tests-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95e68dfc4e682181be588e11c7846ce5cd5edaccc46ebbaa71202d6e4feb232b |
|
MD5 | cffa901eafd1cb04c9fefa51a1fd5ce7 |
|
BLAKE2b-256 | 0c8d507ac094be902829f010b8ca69cb3592b0fa871c4e699617759eea6108ba |
Hashes for django_lightweight_tests-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8a0be5551d462a3fceb2148ef72829b1ca3c0e549688e41e41efb05a06ed58db |
|
MD5 | 6a742c2b0fb29e42855097ec5555aacd |
|
BLAKE2b-256 | db69df95a179745a021cfc35c5f06af3e1e3c75432ef70199291b096913b327e |