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
python -m unittest path_to_suite_function errors #51750
Comments
:!python -m unittest foo.test_suite
Traceback (most recent call last):
File "/usr/lib/python2.6/runpy.py", line 122, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.6/runpy.py", line 34, in _run_code
exec code in run_globals
File "/usr/lib/python2.6/unittest.py", line 875, in <module>
main(module=None)
File "/usr/lib/python2.6/unittest.py", line 816, in __init__
self.parseArgs(argv)
File "/usr/lib/python2.6/unittest.py", line 843, in parseArgs
self.createTests()
File "/usr/lib/python2.6/unittest.py", line 849, in createTests
self.module)
File "/usr/lib/python2.6/unittest.py", line 613, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/usr/lib/python2.6/unittest.py", line 605, in loadTestsFromName
(obj, test))
TypeError: calling <function test_suite at 0x7f748dd6d7d0> returned
<unittest.TestSuite tests=[<foo.TestTask testMethod=test_can_construct>,
<foo.TestTask testMethod=test_can_construct>]>, not a test where foo.py: |
What made you think that would work? In your example foo.test_suite is neither a test nor a suite but a function. |
Its a common convention in zope.testing, trial, testtools, bzr, ... |
So it's a feature request then... |
Sounds like one. As far as the trial behavior goes, "trial foo.test_suite" won't work, but "trial foo" will call "foo.test_suite", if one is defined. |
Is this needed as well as the load_tests protocol? If a test module defines a load_tests function that returns a test suite then the following creates the test suite from load_tests and executes that:
I don't think we need a test_suite protocol as well. |
Use load_tests instead. |
Hi, I think this was misdiagnosed: from unittest.py in 2.6, loadTestFromName:
so it supports callables, such as the test_suite function that I haven't checked what 2.7 and later do, but going on the above
The reason it is not matched is that when run as -m unittest, the unittest module is __main__, and so the TestSuite in the isinstance check is a unittest.TestSuite against a __main__.TestSuite, which won't match. Therefore I think this is a legitimate bug, in at least 2.6. Thanks, James |
Well, it was misdiagnosed yes - but asking for "python -m unittest ..." support in Python 2.6 is still a feature request and not a bug report. (So unfortunately it can't be fixed in 2.6 which is bugfix only. The solution is to use unittest2 or Python 2.7.) |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: