I want to call the Django management command from one of my tests. For this I use django.core.management.call_command . And it does not work.
I have a team with 4 required arguments. When I call it, he complains that all arguments are missing, although I pass them on:
call_command('my_command', url='12', project='abc', website='zbb', title='12345')
I get a basic command error that -url, -project, -website and -title objects are missing.
I did not specify a different destination for these arguments.
I looked at the source of call_command and pointed the problem to the following line in call_command :
if command.use_argparse:
args are positional arguments passed to call_commands, which is empty. I pass only the arguments. parser.parse_args complains that the required variables are missing.
This is in Django 1.8.3.
Here is my add_arguments function command (I just deleted the help lines for short):
def add_arguments(self, parser): parser.add_argument('--url', action='store', required=True) parser.add_argument('--project', action='store', required=True) parser.add_argument('--continue-processing', action='store_true', default=False) parser.add_argument('--website', action='store', required=True) parser.add_argument('--title', action='store', required=True) parser.add_argument('--duplicate', action='store_true',default=False)