Message359949
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 |
|
Date |
User |
Action |
Args |
2020-01-14 07:01:28 | atb00ker | set | recipients:
+ atb00ker, xtreak |
2020-01-14 07:01:28 | atb00ker | set | messageid: <1578985288.37.0.543502426219.issue39283@roundup.psfhosted.org> |
2020-01-14 07:01:28 | atb00ker | link | issue39283 messages |
2020-01-14 07:01:27 | atb00ker | create | |
|