In python setuptools, python setup.py test esegue la suite di test. Tuttavia, se ho un errore di importazione nella mia suite di test, l'unico messaggio di errore che ottengo è un AttributeError che lamenta la mancanza della mia classe di test. C'è un modo per ottenere un messaggio di errore più dettagliato, quindi posso sistemare la suite di test?test di setuptools nasconde errori di importazione. Come avere informazioni migliori?
Mi spiegherò meglio con il seguente esempio. Supponiamo di avere un pacchetto chiamato foo, creato di nuovo con paster. Ho quindi aggiungere il test
./foo
./foo/__init__.py
./foo/tests
./foo/tests/__init__.py
./foo/tests/mytest.py
./setup.cfg
./setup.py
Ora, supponiamo che mytest.py contiene il seguente codice
import unittest
class MyTestClass(unittest.TestCase):
def testFoo(self):
self.assertEqual(1,1)
Questo funziona. Tuttavia, se si tenta di importare un modulo non inesistente
import unittest
import frombiz
class MyTestClass(unittest.TestCase):
def testFoo(self):
self.assertEqual(1,1)
Questo è l'errore che ottengo
Traceback (most recent call last):
File "setup.py", line 26, in <module>
test_suite = "foo.tests"
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/core.py", line 152, in setup
dist.run_commands()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 975, in run_commands
self.run_command(cmd)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/distutils/dist.py", line 995, in run_command
cmd_obj.run()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/command/test.py", line 121, in run
self.with_project_on_sys_path(self.run_tests)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/command/test.py", line 101, in with_project_on_sys_path
func()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/command/test.py", line 130, in run_tests
testLoader = loader_class()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 816, in __init__
self.parseArgs(argv)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 843, in parseArgs
self.createTests()
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 849, in createTests
self.module)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 613, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 587, in loadTestsFromName
return self.loadTestsFromModule(obj)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/Extras/lib/python/setuptools/command/test.py", line 34, in loadTestsFromModule
tests.append(self.loadTestsFromName(submodule))
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/unittest.py", line 584, in loadTestsFromName
parent, obj = obj, getattr(obj, part)
AttributeError: 'module' object has no attribute 'mytest'
In altre parole, non c'è alcun riferimento alle importazioni fallito.
La mia ipotesi è che non c'è alcun modo per ottenere ciò che si vuole senza modificare il codice sorgente di setuptool. – codeape
@codeape - e buona fortuna con quello.:-) –