About the Output of a Management Command

You can call a Django management command programmatically with call_command() function. Check its output by passing a StringIO instance as stdout to it:

1
2
3
4
5
6
from io import StringIO
from django.core.management import call_command

output = StringIO()
call_command("mycommand", verbosity=2, stdout=output)
assert("Success!" in output.getvalue())

Tips and Tricks Programming Development Django 4.2 Django 3.2 Django 2.2 Django 1.11 Django 1.8