Unit Test Profiling for Django 1.3/1.4

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#
# File : profiling.py
#
from django.test.simple import DjangoTestSuiteRunner
from django.conf import settings
from django.utils import unittest


try:
    import cProfile as profile
except ImportError:
    import profile


class DjangoTestSuiteRunnerWithProfile(DjangoTestSuiteRunner):

    def run_suite(self, suite, **kwargs):
        runner = unittest.TextTestRunner(
            verbosity=self.verbosity, failfast=self.failfast).run

        profile.runctx(
            'result = run_tests(suite)',
            {
                'run_tests': runner,
                'suite': suite,
            },
            locals(),
            getattr(settings,'TEST_PROFILE', None)
        )
        return locals()['result']

#
# File : settings.py
#
TEST_RUNNER = 'profiling.DjangoTestSuiteRunnerWithProfile'
TEST_PROFILE = 'unittest.profile'

More like this

  1. Django Admin Speedup for big tables on postgres by potiuk 1 year, 4 months ago
  2. Unit Test Profiling by justquick 5 years, 2 months ago
  3. SELECT FOR UPDATE in Django < 1.4 by joaofrancese 1 year, 10 months ago
  4. nested transactions context manager and decorator by demanzano 2 years, 8 months ago
  5. Profiling Middlware by udfalkso 7 years ago

Comments

(Forgotten your password?)