Skip to content

Instantly share code, notes, and snippets.

@arnaudbos
Created July 30, 2013 13:38
Show Gist options
  • Select an option

  • Save arnaudbos/6112991 to your computer and use it in GitHub Desktop.

Select an option

Save arnaudbos/6112991 to your computer and use it in GitHub Desktop.
Django command wrapper
from optparse import OptionParser
from myapp.management.commands import my_command
def make_test_wrapper_for(command_module):
def _run_cmd_with(*args):
"""Run the possibly_add_alert command with the supplied arguments"""
cmd = command_module.Command()
(opts, args) = OptionParser(option_list=cmd.option_list).parse_args(list(args))
cmd.handle(*args, **vars(opts))
return _run_cmd_with
cmd_runner = make_test_wrapper_for(my_command)
cmd_runner("foo", "bar")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment