homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: unittest returning standard_tests from load_tests in module fails
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: michael.foord Nosy List: michael.foord, r.david.murray
Priority: normal Keywords: easy

Created on 2010年01月28日 18:17 by r.david.murray, last changed 2022年04月11日 14:56 by admin. This issue is now closed.

Messages (3)
msg98469 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010年01月28日 18:17
Working from the example in the docs, I wrote a test suite like this:
def load_tests(loader, standard_tests, pattern):
 for case in email.test.emailtestdb.populated_test_cases(globals()):
 standard_tests.addTests(loader.loadFromTestCase(case))
 return standard_test
This resulted in the exception:
Traceback (most recent call last):
 File "/home/rdmurray/python/bzr/email6-local/Lib/test/regrtest.py", line 857, in runtest_inner
 indirect_test()
 File "/home/rdmurray/python/bzr/email6-local/Lib/test/test_email.py", line 10, in test_main
 tests = unittest.defaultTestLoader.discover(testdir, top_level_dir=libdir)
 File "/home/rdmurray/python/bzr/email6-local/Lib/unittest/loader.py", line 179, in discover
 return self.suiteClass(tests)
 File "/home/rdmurray/python/bzr/email6-local/Lib/unittest/suite.py", line 18, in __init__
 self.addTests(tests)
 File "/home/rdmurray/python/bzr/email6-local/Lib/unittest/suite.py", line 54, in addTests
 self.addTest(test)
 File "/home/rdmurray/python/bzr/email6-local/Lib/unittest/suite.py", line 43, in addTest
 raise TypeError("{} is not callable".format(test))
TypeError: [<unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[]>, <unittest.suite.TestSuite tests=[]>] is not callable
(Well, that's after I enhanced the normal error message, which just says that 'test must be a callable')
I see that loadTestsFromModule wraps what is passes as standard_tests in self.suiteClass before returning it, whereas it returns whatever load_tests returns directly. Perhaps the wrapping needs to be done in both cases, or perhaps standard_tests should be wrapped before being passed to the module's load_tests?
My load_tests is a function in a test module, not a package __init__.
msg98470 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010年01月28日 18:21
Yes. The standard tests should be wrapped in a suite before being passed into load_tests. That's a bug - thanks for catching it.
msg98924 - (view) Author: Michael Foord (michael.foord) * (Python committer) Date: 2010年02月06日 00:24
Fixed in revision 78010.
History
Date User Action Args
2022年04月11日 14:56:57adminsetgithub: 52047
2010年02月06日 00:24:30michael.foordsetstatus: open -> closed
resolution: fixed
messages: + msg98924

stage: test needed -> resolved
2010年01月28日 18:21:01michael.foordsetassignee: michael.foord

messages: + msg98470
nosy: + michael.foord
2010年01月28日 18:17:25r.david.murraycreate

AltStyle によって変換されたページ (->オリジナル) /