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
- New Snippet! by Antoliny0919 4 days, 20 hours ago
- Add Toggle Switch Widget to Django Forms by OgliariNatan 2 months, 3 weeks ago
- get_object_or_none by azwdevops 6 months, 2 weeks ago
- Mask sensitive data from logger by agusmakmun 8 months, 1 week ago
- Template tag - list punctuation for a list of items by shapiromatron 1 year, 10 months ago
Comments
Please login first before commenting.