A test runner for Django unittests which profiles the tests run, and saves the result. Very useful for diagnosing your apps. Place the top portion of the code into a file called profiling.py
someplace in your python path. Update your settings.py
file with the bottom two lines of the code. Now you are ready, so just run python manage.py test [appnames...]
to test any apps listed with profiling. By default this will just print a nice report after the unittests. If you change the value of TEST_PROFILE
to a file, the profile will be saved to that file. The latter is recommended because these profiling reports have a lot of info in them, so it is best to tear through them with the pstats
module.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | # file: profiling.py #
from django.test.simple import run_tests
from django.conf import settings
try:
import cProfile as profile
except ImportError:
import profile
def profile_tests(*args, **kwargs):
profile.runctx('run_tests(*args, **kwargs)',
{'run_tests':run_tests,'args':args,'kwargs':kwargs},
{},
getattr(settings,'TEST_PROFILE',None)
)
# file: settings.py #
TEST_RUNNER = 'profiling.profile_tests'
TEST_PROFILE = None
|
More like this
- Template tag - list punctuation for a list of items by shapiromatron 10 months, 1 week ago
- JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 10 months, 2 weeks ago
- Serializer factory with Django Rest Framework by julio 1 year, 5 months ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 1 year, 6 months ago
- Help text hyperlinks by sa2812 1 year, 6 months ago
Comments
Please login first before commenting.