Search code examples
pythonshellnosenosetests

Passing in arguments to a called script


I'm running nosetests on my project with --with-snort for Growl notifications.

The problem is that I have some lib files that I put on the path, so I have a custom python script at bin/python.

I have no issues running nose via my bin/python by doing which nosetests and using that executable - bin/python /usr/local/bin/nosetests. But now how do I pass in flags to nosetests? Any flags will go to bin/python instead.


Solution

  • What makes you think that flags will go to bin/python? Have you tested this? If I write a simple program to test this out:

    import sys
    print sys.argv[1:]
    

    I get the following ouput from these example calls (assuming I have saved this in a file called test.py)

    python test.py prints []

    python test.py 5 prints ['5']

    python -i test.py 5 prints ['5'] (and then passes control to the interpreter because of the -i flag).

    So flags before the script name are passed to Python, flags after the script name are passed to the script. So in your example, just use

    bin/python /usr/local/bin/nosetests --with-snort
    

    Some of this is convered in Invoking the Interpreter in Python's documentation.