[py-dev] Re: [py-svn] r24998 - py/dist/py/test

François Pinard pinard at iro.umontreal.ca
Tue Mar 28 17:41:51 CEST 2006

[Brian Dorsey]
>On 26/03/06, Carl Friedrich Bolz <cfbolz at gmx.de> wrote:
>> Huh? But a list or args works too, no?

>> def main(args=None):
>>      warn_about_missing_assertion()
>>      if args is None:
>>          args = py.std.sys.argv[1:]
>>      elif isinstance(args, basestring):
>>          args = args.split(" ")
>>      config, args = py.test.Config.parse(args)
>>      ...

>> If args is a list it is passed unchanched to parse. I agree that
>> splitting a string is maybe too magical.

>[...] if args is a list, it passes through the if/elif unchanged. 
>Apologies for missing that!

I do not know if the following comments are relevant to this particular 
patch, or for pylib more generally.

For one of my clients (an all-Python shop), and after good thought, we 
chose a useful convention to be followed by main programs.  Programs 
look like:


    def main(*arguments):


    if __name__ == '__main__':

So, a program may always execute another one by doing:

    import ANOTHER
    ANOTHER.main(ARG1, ARG2, ...)

ARGs are strings in that context, there is no kind of concern about 
matters of shell splitting or escaping.  What is really nice for this 
client is the site-wide uniformity/ubiquity of this convention.  It also 
helps for interactive usage or debugging, even if compared to the shell, 
a few extra commas and string delimiters are required.

Maybe (or maybe not) pylib could give itself a similar approach, quite 
systematically whenever or wherever it makes sense.

P.S. - I simplified the above convention a bit, as we often have, 
instead of "def main(*arguments)", a construct similar to this one:

    class Main:

        def main(self, *arguments):


    run = Main()
    main = run.main

François Pinard   http://pinard.progiciels-bpi.ca

More information about the Pytest-dev mailing list