hRobert12 / python-nose

Automatically exported from code.google.com/p/python-nose
0 stars 0 forks source link

nosetest command line coul not test argparse code #481

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Create a script with Argpase for example :

def main():
    parser = argparse.ArgumentParser(
        description='Some description',
        usage='%(prog)s positional')
    parser.add_argument('positional',
        help='a positional argument')
    args = parser.parse_args()
    print args.positional

2. Begin to write a test for this

def test_main(self):
    from somewhere import main
    main()

(no need for real finished test here as it's break somewhere else)

3. launch the tests with nosetest and one or more arguments

> nosetests --verbose

This will give an error about the argument

#1 test_main (somewhere.tests.blah.Blah) ... usage: nosetests positional
nosetests: error: unrecognized arguments: --verbose
ERROR

[...]
  File "/usr/lib64/python2.7/argparse.py", line 1691, in parse_args
    self.error(msg % ' '.join(argv))
  File "/usr/lib64/python2.7/argparse.py", line 2347, in error
    self.exit(2, _('%s: error: %s\n') % (self.prog, message))
  File "/usr/lib64/python2.7/argparse.py", line 2335, in exit
    _sys.exit(status)

__

I am not sure if it's a python-nose bug or an argparse one.
Something is mixing between the two scripts anyway (mine and nosetests)

Original issue reported on code.google.com by miniw...@gmail.com on 2 Aug 2012 at 6:32

GoogleCodeExporter commented 8 years ago
ArgumentParser is breaking nose's argument parsing.

Original comment by federico...@gmail.com on 2 Jun 2014 at 10:07

GoogleCodeExporter commented 8 years ago
I believe that this is a test issue, you either need to patch sys.argv or pass 
mocked argv as an argument to parse_args().

What you are seeing is that your script is parsing the arguments passed to nose 
(whose arguments it doesn't accept) and is therefore failing.

Original comment by perfectp...@gmail.com on 12 Sep 2014 at 1:22