Tratest上的Pytest失败了:找不到主包

时间:2018-04-02 14:44:12

标签: travis-ci pytest

我最近对Github上的Python 3项目进行了大量更改,主要是文档和文档字符串。

测试在本地传递,但是当我将分支推送到Github时,Travis CI失败了:

$ pytest
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.5.5/lib/python3.5/site-packages/_pytest/config.py", line 342, in _getconftestmodules
    return self._path2confmods[path]
KeyError: local('/home/travis/build/scossu/lakesuperior')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.5.5/lib/python3.5/site-packages/_pytest/config.py", line 373, in _importconftest
    return self._conftestpath2mod[conftestpath]
KeyError: local('/home/travis/build/scossu/lakesuperior/conftest.py')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/travis/virtualenv/python3.5.5/lib/python3.5/site-packages/_pytest/config.py", line 379, in _importconftest
    mod = conftestpath.pyimport()
  File "/home/travis/virtualenv/python3.5.5/lib/python3.5/site-packages/py/_path/local.py", line 668, in pyimport
    __import__(modname)
  File "/home/travis/virtualenv/python3.5.5/lib/python3.5/site-packages/_pytest/assertion/rewrite.py", line 212, in load_module
    py.builtin.exec_(co, mod.__dict__)
  File "/home/travis/build/scossu/lakesuperior/conftest.py", line 6, in <module>
    from lakesuperior.config_parser import test_config
ImportError: No module named 'lakesuperior.config_parser'
ERROR: could not load /home/travis/build/scossu/lakesuperior/conftest.py
The command "pytest" exited with 4.

lakesuperior是主要的应用程序包。

我的.travis.yml

language: python
python:
  - "3.5"
  - "3.6"
install:
  - pip install -r requirements.txt
  - coilmq&
script:
- pytest tests

我认为唯一可能影响导入问题的是我在子包中添加了一些__init__.py文件,以便Sphinx发现API文档。我不知道怎么可能搞乱了CI。

我验证了之前的提交通过了所有测试。

以前有人遇到过这种情况吗?任何提示?

感谢。

1 个答案:

答案 0 :(得分:0)

我最近遇到了同样的问题。我通过从顶级目录中删除__init__.py文件来解决此问题。参见here