my module and unittest contend over commandline options...

Discussion in 'Python' started by chrisber, May 1, 2008.

  1. chrisber

    chrisber Guest

    using the unittest module in Python 2.3.5, I've written some test code
    that ends up with

    if __name__ == "__main__":
    unittest.main()

    Since I want to run this code in various environments, I'd initially
    added some commandline options, e.g. to specify a configuration file
    like so

    test.py -c devtest.conf
    or
    test.py -c localtest.conf

    etc.
    However, unittest also looks for options on the commandline, and it
    was complaining about unrecognized options and quitting.

    I've poked around to see if I could delete the options my earlier code
    consumed from the commandline buffer, before invoking unittest, but
    that seems klugy. Instead, I hardwired in a testing config file name,
    that always has to be local. That works pretty well, but it leaves me
    wonderfing whether there would have been another clean way to allow
    both my test code and unittest to have options without interfering
    with one another.
     
    chrisber, May 1, 2008
    #1
    1. Advertising

  2. chrisber

    chrisber Guest

    On May 2, 4:54 am, Duncan Booth <> wrote:
    > chrisber<> wrote:
    > > ...it leaves me
    > > wonderfing whether there would have been another clean way to allow
    > > both my test code and unittest to have options without interfering
    > > with one another.

    >
    > You can pass argv as a parameter to main(), so I think the best bet is
    > simply to build up a new argv with the options that you want to pass
    > through.


    Aha! I scanned through my python 2.4 installataion and found this in
    unittest
    def __init__(self, module='__main__', defaultTest=None,
    argv=None, testRunner=None,
    testLoader=defaultTestLoader):
    if type(module) == type(''):
    self.module = __import__(module)
    for part in module.split('.')[1:]:
    self.module = getattr(self.module, part)
    else:
    self.module = module
    if argv is None:
    argv = sys.argv

    so I see what you mean. Thanks.
     
    chrisber, May 2, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard
    Replies:
    40
    Views:
    1,370
    Randy Webb
    Dec 19, 2004
  2. Paul  Moore
    Replies:
    1
    Views:
    385
    Paul Moore
    Oct 14, 2008
  3. Skave Rat
    Replies:
    3
    Views:
    99
    Skave Rat
    Sep 10, 2008
  4. Richard

    One fixed....new snag to contend with

    Richard, Dec 17, 2004, in forum: Javascript
    Replies:
    33
    Views:
    288
    Beauregard T. Shagnasty
    Dec 19, 2004
  5. Santosh Kumar
    Replies:
    2
    Views:
    188
    Steven D'Aprano
    Sep 16, 2012
Loading...

Share This Page