Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unittest returning standard_tests from load_tests in module fails #52047

Closed
bitdancer opened this issue Jan 28, 2010 · 3 comments
Closed

unittest returning standard_tests from load_tests in module fails #52047

bitdancer opened this issue Jan 28, 2010 · 3 comments
Assignees
Labels
easy stdlib Python modules in the Lib dir

Comments

@bitdancer
Copy link
Member

BPO 7799
Nosy @bitdancer, @voidspace

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/voidspace'
closed_at = <Date 2010-02-06.00:24:30.666>
created_at = <Date 2010-01-28.18:17:25.566>
labels = ['easy', 'library']
title = 'unittest returning standard_tests from load_tests in module fails'
updated_at = <Date 2010-02-06.00:24:30.664>
user = 'https://github.com/bitdancer'

bugs.python.org fields:

activity = <Date 2010-02-06.00:24:30.664>
actor = 'michael.foord'
assignee = 'michael.foord'
closed = True
closed_date = <Date 2010-02-06.00:24:30.666>
closer = 'michael.foord'
components = ['Library (Lib)']
creation = <Date 2010-01-28.18:17:25.566>
creator = 'r.david.murray'
dependencies = []
files = []
hgrepos = []
issue_num = 7799
keywords = ['easy']
message_count = 3.0
messages = ['98469', '98470', '98924']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'michael.foord']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue7799'
versions = ['Python 2.7', 'Python 3.2']

@bitdancer
Copy link
Member Author

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__.

@bitdancer bitdancer added stdlib Python modules in the Lib dir easy labels Jan 28, 2010
@voidspace
Copy link
Contributor

Yes. The standard tests should be wrapped in a suite before being passed into load_tests. That's a bug - thanks for catching it.

@voidspace voidspace self-assigned this Jan 28, 2010
@voidspace
Copy link
Contributor

Fixed in revision 78010.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

2 participants