[py-dev] branch is being merged back

David Ripton dripton at ripton.net
Mon Apr 18 15:52:36 CEST 2005


On 2005.04.16 21:57:51 +0000, holger krekel wrote:
> Note that the command line options changed slightly, because 
> there is a new rule: py.test will consume all lowercase 
> single-letter options like "-h", "-v", "-x" and so on while
> applications should add only consume capital cased letters. 

Haven't looked at the new code yet, so maybe I'm interpreting your
statement incorrectly, but this seems wrong.

I currently don't rely on the value of sys.argv in unit tests.  If I need 
to test a script that uses argv, I split out a main function from the 
top-level "if __name__ == '__main__'" block and make the latter as small 
and simple as possible (usually just "main()") so I don't have to test it.

Then I do:

def main(argv=sys.argv)

or sometimes even:

def main(argv=None):
    if argv is None:
        argv = sys.argv

So that I have the ability to plug in different argv values for testing, 
without actually hacking the "real" sys.argv

This is occasionally inconvenient.  For example, sometimes a script
requires a password, and you don't want to hardcode it, and you don't
want to put it in a file, and you don't want your test to be overly
interactive, and putting it on the command line feels like the least
insecure of the simple options.  (I know, someone could use ps to sniff
it, so this is hardly super-secure.)

Now, it would be nice to assume that py.test will leave {some of}
sys.argv alone, so that I have the option of using it.

But a rule based on capitalization seems like the wrong way to do this.
I want to pick option names for my programs based on what's
user-friendly, not what my test framework allows.

Maybe a better way to do this would be some kind of
--the-rest-go-to-the-program-under-test option (with a shorter name),
that py.test could use to split sys.argv.  py.test would consume
anything on the command line before the marker, and pass everything
after it to the application as sys.argv

-- 
David Ripton    dripton at ripton.net



More information about the Pytest-dev mailing list