3👍
If you’re already using Fabric for deployment, you can use this snippet from @codeinthehole’s blog post:
from fabric.colors import _wrap_with
green_bg = _wrap_with('42')
red_bg = _wrap_with('41')
# Set the list of apps to test
env.test_apps = "app1 app2"
def test():
with settings(warn_only=True):
result = local('./manage.py test %(test_apps)s --settings=settings_test -v 2 --failfast' % env, capture=False)
if result.failed:
print red_bg("Some tests failed")
else:
print green_bg("All tests passed - have a banana!")
It doesn’t colorise the individual test outputs, but it does give you immediate red / green satisfaction…
21👍
redgreenunittests is the most simple solution and it works great with python 3.x
Install it
pip install redgreenunittest
add the next line into settings.py
TEST_RUNNER = "redgreenunittest.django.runner.RedGreenDiscoverRunner"
and don’t forget to enjoy 🙂
./manage test
- How to get the submitted value of a form in a Django class-based view?
- Saving a Pandas DataFrame to a Django Model
- How can I schedule a Task to execute at a specific time using celery?
- Django global variable
- Django – Delete file from amazon S3
6👍
I found pyrg
to work quite well:
pyrg manage.py test
The required command can be installed with pip:
pip install pyrg
- How show personalized error with get_object_or_404
- Static files won't load when out of debug in Django
- Django models across multiple projects/microservices. How to?
- Can we have Django DateTimeField without timezone?
4👍
I know this is an old question, but django-rainbowtests aims to do this. Failures and Errors are Red, Success is green, and it highlights your project’s code in larger stack traces.
- Why does Django South 1.0 use iteritems()?
- How to purge all tasks of a specific queue with celery in python?
- Change default Django REST Framework home page title
- How to show more than 100 items on each paginated "Change List" page in Django Admin?
3👍
If you’re not using Fabric, you might like redgreenunittest
. Basically, you just put it in the appropriate place in your project (probably in your virtual environment), and then reference it as your TEST_RUNNER
in your settings like this:
TEST_RUNNER="redgreenunittest.django.simple.RedGreenTestSuiteRunner"
If you’re only using Django’s test helper code (mostly django.test.TestCase), then that should do it. otherwise you may need to reference redgreenunittest
directly like so:
import redgreenunittest as unittest
Then you just run your tests. And they’ll have colors. Like magic.
- Django CSRF cookie not set correctly
- How to use ModelMultipleChoiceFilter?
- Why does Django South require a default value when removing a field?
2👍
Take a look at Print in terminal with colors using Python?. You should be able to modify or roll out your own colorization from there.
1👍
- Graphene-python performance issues for large data sets
- Reverse Queryset Order in Django
- Django filter by datetime on a range of dates
- Validating a Django model field based on another field's value?