Closed jruere closed 7 years ago
You are correct, I believe. I have never looked into that feature (in fact, I was barely aware that that feature existed).
It would be good to support the full unittest functionality. If you want to take a crack at submitting a patch, the place to tweak would probably be green/loader.py
in loadFromModule()
and/or loadFromModuleFilename()
.
If not, I may take a crack at it myself after some of the other enhancements.
Note that green
is running the function collector
and load_tests
as test modules.
@jayvdb I cannot tell what what you are trying to say. load_tests
is the function a user would define under the load_tests protocal (which is understandable so far). But I don't know what you mean by collector
and I'm not sure what "running a function as a module" would mean, given that a module is a file containing Python definitions and statements.
Could you clarify what you mean?
Sorry. green
is running the function load_tests
if it exists. Here is a cut down example.
Create this file called test.py
import unittest
def load_tests(loader=unittest.loader.defaultTestLoader,
tests=None, pattern=None):
print('load_tests is run')
try:
tests = loader.loadTestsFromName('test.TestFoo')
suite = unittest.TestSuite()
suite.addTests(tests)
return suite
except Exception as e:
print(e)
raise
class TestFoo(unittest.TestCase):
def test_foo(self):
print('test_foo')
$ green test.py
load_tests is run
load_tests is run
test_foo
Traceback (most recent call last):
File "/usr/bin/green", line 9, in <module>
load_entry_point('green==2.0.7', 'console_scripts', 'green')()
File "/usr/lib/python2.7/site-packages/green/cmdline.py", line 75, in main
result = run(test_suite, stream, args, testing)
File "/usr/lib/python2.7/site-packages/green/runner.py", line 118, in run
result.addProtoTestResult(proto_test_result)
File "/usr/lib/python2.7/site-packages/green/result.py", line 337, in addProtoTestResult
for test, err in proto_test_result.errors:
AttributeError: 'NoneType' object has no attribute 'errors'
Interesting... if load_tests
returns None
, TestFoo
is not run.
import unittest
def load_tests(loader=unittest.loader.defaultTestLoader,
tests=None, pattern=None):
return None
class TestFoo(unittest.TestCase):
def test_foo(self):
print('test_foo')
$ green test.py
Ran 0 tests in 0.124s
No Tests Found
Feature added by @althonos in #160
Included in just-released version 2.9.0.
The unittest module implements the load_tests protocol and this is not supported, AFAICT.
https://docs.python.org/2/library/unittest.html#load-tests-protocol