[ python-Bugs-1742940 ] can't run single lamba funcs as unittest

SourceForge.net noreply at sourceforge.net
Mon Jun 25 18:28:18 CEST 2007


Bugs item #1742940, was opened at 2007-06-25 10:28
Message generated for change (Tracker Item Submitted) made by Item Submitter
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.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1742940&group_id=5470


More information about the Python-bugs-list mailing list