django-rainbowtests 0.7.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,126 @@
1
+ Metadata-Version: 2.4
2
+ Name: django-rainbowtests
3
+ Version: 0.7.0
4
+ Summary: A colorful Django Test Runner.
5
+ Author-email: Brad Montgomery <brad@bradmontgomery.net>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/bradmontgomery/django-rainbowtests
8
+ Project-URL: Repository, https://github.com/bradmontgomery/django-rainbowtests
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Environment :: Web Environment
11
+ Classifier: Framework :: Django
12
+ Classifier: Framework :: Django :: 4.2
13
+ Classifier: Framework :: Django :: 5.2
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3.14
23
+ Classifier: Topic :: Internet :: WWW/HTTP
24
+ Classifier: Topic :: Software Development :: Testing
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Requires-Python: <3.15,>=3.10
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE.md
29
+ License-File: AUTHORS.md
30
+ Requires-Dist: django<5.3,>=4.2
31
+ Requires-Dist: rich
32
+ Dynamic: license-file
33
+
34
+ # django-rainbowtests
35
+
36
+ [![PyPI version](http://img.shields.io/pypi/v/django-rainbowtests.svg?style=flat-square)](https://pypi.python.org/pypi/django-rainbowtests/)
37
+ [![License](http://img.shields.io/pypi/l/django-rainbowtests.svg?style=flat-square)](https://pypi.python.org/pypi/django-rainbowtests/)
38
+ [![CI](https://github.com/bradmontgomery/django-rainbowtests/actions/workflows/ci.yml/badge.svg)](https://github.com/bradmontgomery/django-rainbowtests/actions/workflows/ci.yml)
39
+
40
+ This is a custom test runner for Django that gives you *really* colorful test output.
41
+
42
+ ## Installation
43
+
44
+ Install the latest release with:
45
+
46
+ ```bash
47
+ pip install django-rainbowtests
48
+ ```
49
+
50
+ Or with uv:
51
+
52
+ ```bash
53
+ uv add django-rainbowtests
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ Set your test runner in Django settings:
59
+
60
+ ```python
61
+ TEST_RUNNER = 'rainbowtests.test.runner.RainbowDiscoverRunner'
62
+ ```
63
+
64
+ Then run your tests as usual:
65
+
66
+ ```bash
67
+ python manage.py test
68
+ ```
69
+
70
+ ## Settings
71
+
72
+ ### RAINBOWTESTS_HIGHLIGHT_PATH
73
+
74
+ While running your tests, any lines in your tracebacks that match this path will be highlighted, making them easier to find and read. If you omit this setting, the default is to use the path to your Django installation.
75
+
76
+ ```python
77
+ RAINBOWTESTS_HIGHLIGHT_PATH = '/path/to/my/project/'
78
+ ```
79
+
80
+ ### RAINBOWTESTS_SHOW_MESSAGES
81
+
82
+ If the test output is too verbose and you just want a colorful version of the standard Django test output, set `RAINBOWTESTS_SHOW_MESSAGES` to `False`:
83
+
84
+ ```python
85
+ RAINBOWTESTS_SHOW_MESSAGES = False
86
+ ```
87
+
88
+ ## Python/Django Compatibility
89
+
90
+ - **Python**: 3.10, 3.11, 3.12, 3.13, 3.14
91
+ - **Django**: 4.2, 5.2
92
+
93
+ ## Coverage
94
+
95
+ There is support for [coverage](http://nedbatchelder.com/code/coverage/) via a custom test runner:
96
+
97
+ ```python
98
+ TEST_RUNNER = 'rainbowtests.test.runner.RainbowDiscoverCoverageRunner'
99
+ ```
100
+
101
+ Run your tests as normal (`python manage.py test`), and if you have coverage installed, you should see a report when your tests complete.
102
+
103
+ **Note:** The recommended modern workflow is to use `coverage run manage.py test` directly, which gives you more control over coverage settings.
104
+
105
+ ## Development
106
+
107
+ This project uses [uv](https://github.com/astral-sh/uv) for dependency management.
108
+
109
+ ```bash
110
+ # Clone the repository
111
+ git clone https://github.com/bradmontgomery/django-rainbowtests.git
112
+ cd django-rainbowtests
113
+
114
+ # Install dependencies
115
+ uv sync --group dev --group test
116
+
117
+ # Run tests
118
+ uv run pytest
119
+
120
+ # Run linter
121
+ uv run ruff check .
122
+ ```
123
+
124
+ ## License
125
+
126
+ MIT. See [LICENSE.md](LICENSE.md).
@@ -0,0 +1,16 @@
1
+ django_rainbowtests-0.7.0.dist-info/licenses/AUTHORS.md,sha256=uM6XPteuuZK0HovBjaj6nEGEwWez9HFrN5gjvw5lCsI,241
2
+ django_rainbowtests-0.7.0.dist-info/licenses/LICENSE.md,sha256=a5-eAdWDWiNkVLSmn_dEKpG89Dwn8oALECf3sBqBeLM,1101
3
+ rainbowtests/__init__.py,sha256=09hol5ovL6ArILJIJZ-MiscnOjKa6RjaETmtdgJpW2c,22
4
+ rainbowtests/colors.py,sha256=xnwEeR7dsh4ML-7P56IVinaCDHMfOCH0Lfbnl7qGpHE,782
5
+ rainbowtests/messages.py,sha256=ydzl7wX5HAhtbah__u1lx4mqwRtLL4W5A2kD31aKK0c,1194
6
+ rainbowtests/models.py,sha256=o9OLSqCjxl-f58x1NghptLZ54jnJelBqJUiOVQBmwuQ,27
7
+ rainbowtests/tests.py,sha256=MCoe8F46VOIBex3QeXlsxbuoClDuJKWVbsrzonBeBUc,21
8
+ rainbowtests/views.py,sha256=F42JXgnqFqK0fajXeutyJJxwOszRxoLMNkIhfc4Z7KI,26
9
+ rainbowtests/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ rainbowtests/test/core.py,sha256=AuGa7D-4MWNXvvp3V-BMx13JLIk-3Qx2srMaCnn_ygI,4267
11
+ rainbowtests/test/runner.py,sha256=1qWqiX_mm9dnd4E94WCfYqAreRuRt_562bnTgDvCVko,1911
12
+ rainbowtests/test/simple.py,sha256=kG1Wyphm9lyiN_QjkDPIVHu3vc8_sPUAVV5BA8t3H3w,737
13
+ django_rainbowtests-0.7.0.dist-info/METADATA,sha256=NogvpkKNI4bGqdWgFGey50vfjXyeCxsR2z5Rrq3_S7M,3791
14
+ django_rainbowtests-0.7.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ django_rainbowtests-0.7.0.dist-info/top_level.txt,sha256=zGlNAlfW5fEIlxoIIOID7wkmpzsA6OSUKc9mligl2L8,13
16
+ django_rainbowtests-0.7.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,6 @@
1
+ # Authors & Contributors
2
+
3
+ - Brad Montgomery (<https://github.com/bradmontgomery>)
4
+ - Aaron Bassett (<https://github.com/aaronbassett>)
5
+ - Michael Allen (<https://github.com/michaeldfallen>)
6
+ - Paul Cochrane (<https://github.com/paultcochrane>)
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2026, Brad Montgomery <brad@bradmontgomery.net>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ rainbowtests
@@ -0,0 +1 @@
1
+ __version__ = '0.7.0'
rainbowtests/colors.py ADDED
@@ -0,0 +1,31 @@
1
+ import io
2
+
3
+ from rich.console import Console
4
+ from rich.text import Text
5
+
6
+
7
+ def _make_style(style: str):
8
+ """Create a styling function using rich.
9
+
10
+ Returns a callable that applies the given rich style to text and
11
+ returns an ANSI-colored string.
12
+ """
13
+
14
+ def styler(text: str) -> str:
15
+ if not text:
16
+ return ""
17
+ t = Text(text, style=style)
18
+ console = Console(file=io.StringIO(), force_terminal=True, no_color=False)
19
+ console.print(t, end="")
20
+ return console.file.getvalue()
21
+
22
+ return styler
23
+
24
+
25
+ blue = _make_style("bold blue")
26
+ cyan = _make_style("bold cyan")
27
+ green = _make_style("green")
28
+ magenta = _make_style("bold magenta")
29
+ red = _make_style("bold red")
30
+ white = _make_style("bold white")
31
+ yellow = _make_style("bold yellow")
@@ -0,0 +1,64 @@
1
+ """Fun messages for test results."""
2
+
3
+ from random import choice
4
+
5
+ from rainbowtests import colors
6
+
7
+ happy_messages = []
8
+ sad_messages = []
9
+
10
+ happy_messages.append("""
11
+
12
+ (づ。◕‿‿◕。)づ・。*。✧・゜・。
13
+ ✧。*・゜゜・✧。・゜゜SUCCESS!!・。
14
+ *。・゜*✧✿。*。✧・゜゜・✧。✧。*・
15
+
16
+ """)
17
+
18
+ happy_messages.append("""
19
+
20
+ (☞゚∀゚)☞ You rock!
21
+ All tests passed.
22
+
23
+ """)
24
+
25
+ happy_messages.append("""
26
+
27
+ ヽ(´▽`)/ Hallelujah!
28
+ Praise FSM. Success.
29
+
30
+ """)
31
+
32
+ happy_messages.append("""
33
+
34
+ (。♥‿♥。) ・。♥。✧・゜・✿
35
+ ✧。*・Your code loves you.✧♥
36
+ ✿。・ All tests passed!✿。*
37
+ ✧・゜♥・✧。♥。*・。♥。✧・♥・✿
38
+ """)
39
+
40
+ sad_messages.append("""
41
+
42
+ (╯°□°)╯︵ ┻━┻
43
+ AAAAAAAAAARGGGGGGGGGG!!!
44
+
45
+ """)
46
+
47
+ sad_messages.append("""
48
+
49
+ ლ(ಠ益ಠლ)
50
+ Bloody tests failed AGAIN!
51
+
52
+ """)
53
+
54
+
55
+ def random_happy():
56
+ return colors.green(choice(happy_messages))
57
+
58
+
59
+ def random_sad():
60
+ return colors.red(choice(sad_messages))
61
+
62
+
63
+ def random(success):
64
+ return random_happy() if success else random_sad()
rainbowtests/models.py ADDED
@@ -0,0 +1 @@
1
+ # Create your models here.
File without changes
@@ -0,0 +1,116 @@
1
+ """Core test result and output classes for rainbowtests."""
2
+
3
+ import sys
4
+ import unittest
5
+ from inspect import getfile
6
+ from os.path import dirname
7
+
8
+ import django
9
+ from django.conf import settings
10
+
11
+ from rainbowtests import colors
12
+
13
+
14
+ class ColorfulOut:
15
+ """Wrapper around sys.stdout to make its output colorful."""
16
+
17
+ def write(self, arg, **kwargs):
18
+ return sys.stdout.write(colors.blue(arg), **kwargs)
19
+
20
+
21
+ class RainbowTextTestResult(unittest.runner.TextTestResult):
22
+ """The color-enhanced Text output for a test run."""
23
+
24
+ def __init__(self, *args, **kwargs):
25
+ super().__init__(*args, **kwargs)
26
+ self._set_highlight_path()
27
+
28
+ def _set_highlight_path(self):
29
+ """Determine what path to code we should highlight in a Traceback."""
30
+ try:
31
+ self.highlight_path = settings.RAINBOWTESTS_HIGHLIGHT_PATH
32
+ except AttributeError:
33
+ # Highlight packages installed alongside django
34
+ self.highlight_path = dirname(getfile(django))
35
+
36
+ def addSuccess(self, test):
37
+ unittest.TestResult.addSuccess(self, test)
38
+ if self.showAll:
39
+ self.stream.writeln(colors.green("ok"))
40
+ elif self.dots:
41
+ self.stream.write(colors.green("."))
42
+ self.stream.flush()
43
+
44
+ def addError(self, test, err):
45
+ unittest.TestResult.addError(self, test, err)
46
+ if self.showAll:
47
+ self.stream.writeln(colors.red("ERROR"))
48
+ elif self.dots:
49
+ self.stream.write(colors.red('E'))
50
+ self.stream.flush()
51
+
52
+ def addFailure(self, test, err):
53
+ unittest.TestResult.addFailure(self, test, err)
54
+ if self.showAll:
55
+ self.stream.writeln(colors.red("FAIL"))
56
+ elif self.dots:
57
+ self.stream.write(colors.red('F'))
58
+ self.stream.flush()
59
+
60
+ def printErrorList(self, flavour, errors):
61
+ """Print colorful test output:
62
+
63
+ * Error and Failure headers are in Red.
64
+ * The First/Last lines (Traceback heading and Exception) are Cyan.
65
+ # Non-Django lines are Yellow.
66
+
67
+ """
68
+
69
+ for test, err in errors:
70
+ self.stream.writeln(colors.red(self.separator1))
71
+ out = "{0}: {1}".format(flavour, self.getDescription(test))
72
+ self.stream.writeln(colors.red(out))
73
+ self.stream.writeln(colors.red(self.separator2))
74
+ tb = "{0}".format(err)
75
+ lines = tb.strip().split("\n")
76
+
77
+ # Temporarily remove the first & last lines of the Traceback.
78
+ if len(lines) > 2:
79
+ first_line = colors.cyan(lines.pop(0)) # Traceback header
80
+ last_line = colors.cyan(lines.pop(-1)) # The Exception
81
+ else:
82
+ first_line, last_line = ('', '')
83
+
84
+ # Python 2 tracebacks are organized into pairs of lines--a path and
85
+ # a line of code that looks something like this:
86
+ #
87
+ # >>> File "/path/to/module.py", line 123, in method_name
88
+ # >>> some_line_of_code
89
+ #
90
+ # Python 3 tracebacks, however, may start with several lines of
91
+ # output, e.g.:
92
+ #
93
+ # -----------------------------------------------------------------
94
+ # Traceback (most recent call last):
95
+ # File "/usr/lib/python/unittest/mock.py", line 1, in _whatever
96
+ # return getattr(thing, comp)
97
+ # AttributeError: 'module' object has no attribute 'something'
98
+ #
99
+ # During handling of the above exception, another exception occurred
100
+ #
101
+ # -----------------------------------------------------------------
102
+ #
103
+ # So, rather than trying to group every two lines (like this code
104
+ # used to do), just inspect each line and if we watch a given
105
+ # path, highlight it and the next line of the traceback.
106
+
107
+ i = 0
108
+ while i < len(lines) - 1:
109
+ if self.highlight_path in lines[i]:
110
+ lines[i] = colors.yellow(lines[i])
111
+ lines[i + 1] = colors.yellow(lines[i + 1])
112
+ i += 1
113
+
114
+ lines.insert(0, first_line)
115
+ lines.append(last_line)
116
+ self.stream.writeln("\n".join(lines))
@@ -0,0 +1,63 @@
1
+ """Rainbow test runners for Django."""
2
+
3
+ import unittest
4
+
5
+ from django.conf import settings
6
+ from django.test.runner import DiscoverRunner
7
+
8
+ from rainbowtests import messages
9
+ from rainbowtests.test.core import ColorfulOut, RainbowTextTestResult
10
+
11
+ try:
12
+ import coverage
13
+ except ImportError:
14
+ coverage = None
15
+
16
+
17
+ class RainbowDiscoverRunner(DiscoverRunner):
18
+ """Replacement for Django's DiscoverRunner."""
19
+
20
+ def __init__(self, *args, **kwargs):
21
+ super().__init__(*args, **kwargs)
22
+ self._set_messages_display()
23
+
24
+ def _set_messages_display(self):
25
+ """Don't show messages if the user doesn't want them"""
26
+ try:
27
+ self.show_messages = settings.RAINBOWTESTS_SHOW_MESSAGES
28
+ except AttributeError:
29
+ self.show_messages = True
30
+
31
+ def run_suite(self, suite, **kwargs):
32
+ if not hasattr(self, "test_runner"):
33
+ # This was added as a clas attribute in Django 1.7
34
+ self.test_runner = unittest.TextTestRunner
35
+
36
+ runner = self.test_runner(
37
+ verbosity=self.verbosity,
38
+ failfast=self.failfast,
39
+ )
40
+ runner.resultclass = RainbowTextTestResult
41
+ result = runner.run(suite)
42
+
43
+ if self.show_messages:
44
+ runner.stream.writeln(messages.random(result.wasSuccessful()))
45
+ return result
46
+
47
+
48
+ class RainbowDiscoverCoverageRunner(RainbowDiscoverRunner):
49
+ """Replacement for Django's DiscoverRunner with coverage support."""
50
+
51
+ def __init__(self, *args, **kwargs):
52
+ super().__init__(*args, **kwargs)
53
+ self._cov = None
54
+ if coverage:
55
+ self._cov = coverage.Coverage()
56
+ self._cov.start()
57
+
58
+ def suite_result(self, suite, result, **kwargs):
59
+ result = super().suite_result(suite, result, **kwargs)
60
+ if coverage and self._cov:
61
+ self._cov.stop()
62
+ self._cov.report(file=ColorfulOut())
63
+ return result
@@ -0,0 +1,23 @@
1
+ """Legacy test runner for Django < 1.8.
2
+
3
+ This module is deprecated and will raise an error if used.
4
+ DjangoTestSuiteRunner was removed in Django 1.8.
5
+
6
+ Use rainbowtests.test.runner.RainbowDiscoverRunner instead.
7
+ """
8
+
9
+
10
+ class RainbowTestSuiteRunner:
11
+ """Deprecated: This runner is not compatible with Django 1.8+.
12
+
13
+ DjangoTestSuiteRunner was removed in Django 1.8. Please use
14
+ RainbowDiscoverRunner instead:
15
+
16
+ TEST_RUNNER = 'rainbowtests.test.runner.RainbowDiscoverRunner'
17
+ """
18
+
19
+ def __init__(self, *args, **kwargs):
20
+ raise NotImplementedError(
21
+ "RainbowTestSuiteRunner is not compatible with Django 1.8+. "
22
+ "Please use 'rainbowtests.test.runner.RainbowDiscoverRunner' instead."
23
+ )
rainbowtests/tests.py ADDED
@@ -0,0 +1 @@
1
+ # Test *this* thing.
rainbowtests/views.py ADDED
@@ -0,0 +1 @@
1
+ # Create your views here.