Hello everyone,
I was working on a admin command today, and when setting up tests and fixtures for running the command during testing I found this error:
Traceback (most recent call last):
File "/home/fjm/code/django-stuff/tutorial/polls/tests.py", line 10, in test_command_output
call_command("closepoll", poll_ids=1, stdout=out)
File "/home/fjm/.local/share/virtualenvs/tutorial/lib/python3.10/site-packages/django/core/management/__init__.py", line 168, in call_command
parse_args.append(min(opt.option_strings), default=0)
ValueError: min() arg is an empty sequence
However, what is weird is that when run from with the manage.py script, everything seems to be working just fine.
This is the command code
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("poll_ids", nargs="+", type=int)
def handle(self, *args, **options):
pass
And this is the test code:
from io import StringIO
from django.core.management import call_command
from django.test import SimpleTestCase
class ClosepollTest(SimpleTestCase):
def test_command_output(self):
out = StringIO()
call_command("closepoll", poll_ids=1, stdout=out)
self.assertIn("Expected output", out.getvalue())
Is this a bug? Am I doing something wrong? Have I missed anything?
I checked the bug tracker but could not find anything related to this and before opening an issue I figured I'd ask. If it is indeed a bug I will happily write a ticket in the tracker.
Thanks in advance.