使用unittest discover启动的测试无法导入某些模块

时间:2015-06-02 14:57:21

标签: python python-2.7 unit-testing

所以我从头做了一个python项目,我的测试在eclipse / pydev中运行正常但是当我使用discover命令行时它们没有。

结构:

The project structure

运行discover命令时我得到了什么:

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
你知道吗? 感谢。

修改

我尝试在每个测试用例中自己加载src文件夹,但它不起作用

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

0 个答案:

没有答案