mercredi 3 juin 2015

Test launched with unittest discover can't import some module

So I have made a python project from scratch, my tests works fine in eclipse/pydev however they do not when I'm using the discover command line.

Structure :

The project structure

And what I'm getting when running the discover command :

qzdqzdqzd@dgdrgdrrdg /d/AAA_Dev2015/Checkouts/web/tools/ideal-checker/tests (cpatitest)
$ python -m unittest discover -v -p '*_test.py'
core.configloader_test (unittest.loader.ModuleImportFailure) ... ERROR
ideal.idealtagger_test (unittest.loader.ModuleImportFailure) ... ERROR
ideal.rcprovider_test (unittest.loader.ModuleImportFailure) ... ERROR

======================================================================
ERROR: core.configloader_test (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: core.configloader_test
Traceback (most recent call last):
  File "c:\Python27\lib\unittest\loader.py", line 252, in _find_tests
    module = self._get_module_from_name(name)
  File "c:\Python27\lib\unittest\loader.py", line 230, in _get_module_from_name
    __import__(name)
  File "d:\AAA_Dev2015\Checkouts\web\tools\ideal-checker\tests\core\configloader_test.py", line 7, in <module>
    import testutil
  File "d:\AAA_Dev2015\Checkouts\web\tools\ideal-checker\tests\testutil.py", line 4, in <module>
    import util
ImportError: No module named util


======================================================================
ERROR: ideal.idealtagger_test (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: ideal.idealtagger_test
Traceback (most recent call last):
  File "c:\Python27\lib\unittest\loader.py", line 252, in _find_tests
    module = self._get_module_from_name(name)
  File "c:\Python27\lib\unittest\loader.py", line 230, in _get_module_from_name
    __import__(name)
  File "d:\AAA_Dev2015\Checkouts\web\tools\ideal-checker\tests\ideal\idealtagger_test.py", line 8, in <module>
    import testutil
  File "d:\AAA_Dev2015\Checkouts\web\tools\ideal-checker\tests\testutil.py", line 4, in <module>
    import util
ImportError: No module named util


======================================================================
ERROR: ideal.rcprovider_test (unittest.loader.ModuleImportFailure)
----------------------------------------------------------------------
ImportError: Failed to import test module: ideal.rcprovider_test
Traceback (most recent call last):
  File "c:\Python27\lib\unittest\loader.py", line 252, in _find_tests
    module = self._get_module_from_name(name)
  File "c:\Python27\lib\unittest\loader.py", line 230, in _get_module_from_name
    __import__(name)
  File "d:\AAA_Dev2015\Checkouts\web\tools\ideal-checker\tests\ideal\rcprovider_test.py", line 7, in <module>
    import testutil
  File "d:\AAA_Dev2015\Checkouts\web\tools\ideal-checker\tests\testutil.py", line 4, in <module>
    import util
ImportError: No module named util

You thoughts? Thanks.

EDIT

I tried loading the src folder myself in each test case but it did not work

@classmethod
def setUpClass(cls):
    sys.path.insert(0, '../../src')

Aucun commentaire:

Enregistrer un commentaire