This is hardcoded to use django-discover-runner since that's my main test runner but could easily be adopted to use Django's own test runner. If you're using a terminal that is capable of showing 256 colors use the Terminal256Formatter
formatter instead.
Enabled it with the TEST_RUNNER
setting:
TEST_RUNNER = 'dotted.path.to.highlighted.runner.HighlightedDiscoverRunner'
Where dotted.path.to.highlighted.runner
is the Python import path of the file you saved the runner in.
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 | from pygments import highlight
from pygments.lexers import PythonTracebackLexer
from pygments.formatters import TerminalFormatter
from django.utils.unittest import TextTestRunner, TextTestResult
from discover_runner import DiscoverRunner
class HighlightedTextTestResult(TextTestResult):
def _exc_info_to_string(self, err, test):
code = super(HighlightedTextTestResult, self)._exc_info_to_string(err, test)
return highlight(code, PythonTracebackLexer(), TerminalFormatter())
class HighlightedTextTestRunner(TextTestRunner):
resultclass = HighlightedTextTestResult
class HighlightedDiscoverRunner(DiscoverRunner):
def run_suite(self, suite, **kwargs):
return HighlightedTextTestRunner(
verbosity=self.verbosity, failfast=self.failfast).run(suite)
|
More like this
- Browser-native date input field by kytta 1 month, 1 week ago
- Generate and render HTML Table by LLyaudet 1 month, 2 weeks ago
- My firs Snippets by GutemaG 1 month, 3 weeks ago
- FileField having auto upload_to path by junaidmgithub 2 months, 4 weeks ago
- LazyPrimaryKeyRelatedField by LLyaudet 3 months ago
Comments
This would be really useful to have in the standard Django testrunner! :-)
#
This is now the standard test runner!
#
as django-discover-runner now comes with django (since 1.6), you should replace
by
#
Please login first before commenting.