Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing arguments to nosetest

I write my nose unit tests to be fairly complete, but as a result they can take a while to run. I would like to be able to pass in an optional command-line argument to run some quick version of the tests (e.g. try a handful of possible inputs, instead of every possible input).

Ideally, I'd be able to say something like:

nosetest --quick my_module/tests/my_test.py

And in my_test.py, have:

def test_something():
    if nose.command_line_args.quick:
        <run quick test>
    else:
        <run long test>

Is there a simple way to do this? I know that one way might be to write a nose plugin, but I got scared away when the docs said I needed to install any plugins I write using setuptools. Learning setuptools to install a nose plugin all to just pass in a flag is a bit of yak-shaving I'd love to avoid if I can.

like image 346
SuperElectric Avatar asked Jan 26 '26 17:01

SuperElectric


1 Answers

I don't think nosetests offers any way for you to add custom command-line options (except that of course you can edit its code to customize it for you, but that may not be practical).

In typical Unixy shells, however, you can set environment variables on the fly for any given command:

$ NOSEQUICK=1 nosetests my_module/tests/my_test.py

then in your code you can check if os.getenv('NOSEQUICK', ''):.

like image 158
Alex Martelli Avatar answered Jan 28 '26 08:01

Alex Martelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!