Created
September 27, 2021 10:54
-
-
Save bennett39/5123d3c619169cb02af42d330ff9c599 to your computer and use it in GitHub Desktop.
Testing Django Admin Commands
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from io import StringIO | |
from django.core.management import call_command | |
from django.test import TestCase | |
class MyCommandTest(TestCase): | |
def test_my_command(self): | |
out = StringIO() # <-- Use StringIO to capture the output of the command from stdout | |
args = [] # <-- Any command line arguments go here | |
kwargs = {'stdout': out} # <-- Any named command line options (e.g. --my-option) go here | |
call_command('my_command', *args, **kwargs) | |
# Add assertions here... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment