Bugs item #1742940, was opened at 2007-06-25 10:28 Message generated for change (Comment added) made by tctimmeh You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1742940&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: timmeh (tctimmeh) Assigned to: Nobody/Anonymous (nobody) Summary: can't run single lamba funcs as unittest Initial Comment: 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. ---------------------------------------------------------------------- >Comment By: timmeh (tctimmeh) Date: 2007-06-25 15:57 Message: Logged In: YES user_id=1827855 Originator: YES Here is code that causes the problem: import unittest class Exmpl(unittest.TestCase): pass Exmpl.testBug = lambda self: 1+2 if (__name__ == '__main__'): unittest.main() Running "program.py" with no args is an error free run. Running "program.py Exmpl.testBug" dies with the stack trace mentioned above. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1742940&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com