unit testing - Can not run nosetests when i use argparse in my python code -
in main code had this:
#comp.py parser = argumentparser() parser.add_argument("-n", dest="deg", default=100,type=int, help="setup value of deg") parser.add_argument("-k", dest="k", default=25, type=float, help="setup value of k") parser.add_argument("-l", dest="l", default=0, type=int, help="setup value of l") args = parser.parse_args() def afunc(x): ... #do k, l, deg , homecoming result ... homecoming result in verify.py might this:
#verify.py import unittest import comp class testfuncs(unittest.testcase): def test_afunc(self): self.assertequal(afunc(0), 0) self.assertequal(afunc(1), 0) self.assertequal(afunc(1), 1) self.assertequal(afunc(3.2), 1) ... and when tried run nosetests test result of function a in comp.py. got error:
machine:project user$ nosetests verify usage: nosetests [-h] [-n deg] [-k k] [-l l] nosetests: error: unrecognized arguments: verify how solve problem?
ok, solved added few lines if else condition
it seems test file (verify.py) can not manage value assignment in parser part in code (comp.py). add together status below assign values of deg, k, l in case of comp.py doesn't run main function.
#comp.py if __name__ == "__main__": parser = argumentparser() parser.add_argument("-n", dest="deg", default=100,type=int, help="setup value of deg") parser.add_argument("-k", dest="k", default=25, type=float, help="setup value of k") parser.add_argument("-l", dest="l", default=0, type=int, help="setup value of l") args = parser.parse_args() else: deg=100 k=25 l=0 def afunc(x): ... #do k, l, deg , homecoming result ... homecoming result python unit-testing parsing command-line nosetests
No comments:
Post a Comment