ddinchev ddinchev - 1 year ago 110
Python Question

Flask-Script command that passes all remaining args to nose?

I use a simple command to run my tests with nose:

def test():
"""Run unit tests."""
import nose

However, nose supports many useful arguments that now I could not pass.

Is there a way to run nose with manager command (similar to the call above) and still be able to pass arguments to nose? For example:

python manage.py test --nose-arg1 --nose-arg2

Right now I'd get an error from
--nose-arg1 --nose-arg2
are not recognised as valid arguments. I want to pass those args as
nose.main(argv= <<< args comming after python manage.py test ... >>>)

Answer Source

Flask-Script has an undocumented capture_all_flags flag, which will pass remaining args to the Command.run method. This is demonstrated in the tests.

class NoseCommand(Command):
    name = 'test'
    capture_all_args = True

    def run(self, remaining):
python manage.py test --nose-arg1 --nose-arg2
# will call nose.main(argv=['--nose-arg1', '--nose-arg2'])
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download