My team runs a custom test suite pretty regularly. When we want to run the whole thing, we do
./manage.py test --keepdb --failfast --settings=AE.test_settings
When we want to run tests on a specific app, we do the same, but with the app name include.
I'd like to make a custom management command that, when called, will run the default test suite, but append the --keepdb, --failfast, and --settings=AE.test_settings params. Ideally something like
./manage.py aetest
That can also be run with app names, such that
./manage.py aetest registration
Would be the same as running
./manage.py test registration --keepdb --failfast --settings=AE.test_settings
My attempt so far is
from django.core.management.base import BaseCommand, CommandError
from django.core import management
class Command(BaseCommand):
def handle(self, *args, **kwargs):
positional_arguments = [
'--keepdb',
'--failfast',
'--settings=NJ.test_settings',
]
for item in args:
positional_arguments.append(item)
keyword_arguments = {
'settings': "AE.test_setings",
}
keyword_arguments.update(kwargs)
management.call_command("test", *positional_arguments, **keyword_arguments)
If I try to pass further positional arguments, my command errors out in such a way as to imply they were never passed. And the keyword argument never makes it to the call_command (the command runs with my default settings.py file)
Any idea how I can have this management command accept additional positional and keyword parameters, but append the desired ones automatically?
Thanks!
Aucun commentaire:
Enregistrer un commentaire