Ajay Tripathi <ajay3...@gmail.com> added the comment:
Hi, Thanks for your response, here is a code sample of what I am doing right now: ``` import unittest import sys class MyTest(unittest.TestCase): def __init__(self, testName, extraArg): super(MyTest, self).__init__(testName) self.myExtraArg = extraArg def test_something(self): print(self.myExtraArg) extraArg = sys.argv.pop() suite = unittest.TestSuite() suite.addTest(MyTest('test_something', extraArg)) unittest.TextTestRunner(verbosity=2).run(suite) ``` It works. However, this can be cumbersome if there are a lot of "extraArgs" and MyTestClasses. Especically, if there is an existing argparser function existing that is used in the program, re-writing the code for passing args in another way for unittest doesn't seem ideal. Ideally, I think something like this may work perfectly: ``` import unittest class SomethingLikeInheritedUnitest(unittest.TestProgram): # parent_parser is used here: https://github.com/python/cpython/blob/master/Lib/unittest/main.py#L162 parent = super().createParentArgParserAndReturnIt() parser = argparse.ArgumentParser(parents=[parent]) parser.add_argument('--myarg1', ...) parser.add_argument('--myarg2', ...) return parser ``` Now the parser may be exposed to user's MyTest class and they can use arguements as: `paser.myarg1` Note: I am not certain this may be the way to go about it, there may be a better way, infact, I've not even had the time to read the entire code. :-( I am only trying to point out is that the ability to add `myarg1` in the parent_parser may be useful at times. Hope this makes the point a bit more clear. If I have misunderstood something please correct me. Thank You, Ajay Tripathi ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39283> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com