I have some code that adds new test funtions to a TestCase class as lambda functions:
ExmplTests.myTest = lambda: 1+2
When I run the app and specify my lamba test to run, as in:
myTestProg ExmplTests.mytest
I get:
Traceback (most recent call last):
File "C:\work\CTTS\o-ticket\scOmniCTTS\test\otfbatch_test.py", line 188, in ?
unittest.main(defaultTest = 'suite')
File "C:\Python24\lib\unittest.py", line 761, in __init__
self.parseArgs(argv)
File "C:\Python24\lib\unittest.py", line 788, in parseArgs
self.createTests()
File "C:\Python24\lib\unittest.py", line 794, in createTests
self.module)
File "C:\Python24\lib\unittest.py", line 559, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "C:\Python24\lib\unittest.py", line 543, in loadTestsFromName
return parent(obj.__name__)
File "C:\Python24\lib\unittest.py", line 211, in __init__
raise ValueError, "no such test method in %s: %s" % \
ValueError: no such test method in <class '__main__.ExmplTests'>: <lambda>
It seems this is the case because lamba functions are always named '<lamba>'. If I change unittest.py ln543 from:
return parent(obj.__name__)
to:
return parent(part)
it fixes my problem because part has the function name as a string, instead of getting it from obj, which returns '<lambda>' in my case.
|