Last active
March 30, 2021 12:46
-
-
Save zzantares/d2b7553feb0fd900a79112fd8e5cd4d5 to your computer and use it in GitHub Desktop.
Profiling django tests, read more at https://pymotw.com/2/profile/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# based on https://djangosnippets.org/snippets/1315/ | |
from django.conf import settings | |
from django.test.runner import DiscoverRunner | |
try: | |
import cProfile as profile | |
except ImportError: | |
import profile | |
class ProfilingRunner(DiscoverRunner): | |
def run_tests(self, *args, **kwargs): | |
s = super(ProfilingRunner, self) | |
profile.runctx( | |
'run_tests(*args, **kwargs)', | |
{ | |
'run_tests': s.run_tests, | |
'args': args, | |
'kwargs': kwargs | |
}, | |
{}, | |
getattr(settings, 'TEST_PROFILE', None)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST_RUNNER = 'profiling.ProfilingRunner' | |
TEST_PROFILE = None # Set to a file path to create a pstats readable binary |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment