Danke, aber habe ich mit dem folgende Code Probleme:
Code: Alles auswählen
import argparse
import unittest
def add(a,b): return a+b
def mult(a,b): return a*b
class TestCalculator(unittest.TestCase):
def test_add(self):
self.assertEqual( 4, add(1,3))
self.assertEqual( 0, add(0,0))
self.assertEqual(-3, add(-1,-2))
def test_mult(self):
self.assertEqual( 3, mult(1,3))
self.assertEqual( 0, mult(0,3))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--test', help='Test calculater')
args = parser.parse_args()
if args.test:
unittest.main()
else:
print 'do something'
Ich bekomme folgende erros
1.)
$ python __init__.py --test
usage: __init__.py [-h] [--test TEST]
__init__.py: error: argument --test: expected one argument
2.)
$ python __init__.py --test TestCalculator
option --test not recognized
Usage: __init__.py [options] [test] [...]
Options:
-h, --help Show this message
-v, --verbose Verbose output
-q, --quiet Minimal output
-f, --failfast Stop on first failure
-c, --catch Catch control-C and display results
-b, --buffer Buffer stdout and stderr during test runs
Examples:
__init__.py - run default set of tests
__init__.py MyTestSuite - run suite 'MyTestSuite'
__init__.py MyTestCase.testSomething - run MyTestCase.testSomething
__init__.py MyTestCase - run all 'test*' test methods
in MyTestCase
Wie bekommt es zum laufen?