当我在本地运行测试时它的工作正常,但是在创建docker并在容器内运行后,我得到了错误。在运行py.test时出现错误ImportMismatchError
/usr/local/lib/python3.5/site-packages/_pytest/config.py:325: in _getconftestmodules
return self._path2confmods[path]
E KeyError: local('/apis/db/tests')
During handling of the above exception, another exception occurred:
/usr/local/lib/python3.5/site-packages/_pytest/config.py:356: in _importconftest
return self._conftestpath2mod[conftestpath]
E KeyError: local('/apis/db/tests/conftest.py')
During handling of the above exception, another exception occurred:
/usr/local/lib/python3.5/site-packages/_pytest/config.py:362: in _importconftest
mod = conftestpath.pyimport()
/usr/local/lib/python3.5/site-packages/py/_path/local.py:680: in pyimport
raise self.ImportMismatchError(modname, modfile, self)
_pytest.config.ConftestImportFailure: ImportMismatchError('conftest', '/projects/my_project/db/tests/conftest.py', local('/apis/db/tests/conftest.py'))
/apis - 它是Dockerfile中的WORKDIR。
你可能有一些python导入路径或符号链接或其他问题。什么是/ projects/my_project和什么是/ apis?他们是目录还是符号链接?他们如何相互关联? – MarSoft
@MarSoft/projects位于主目录中,/ apis位于docker的主目录中,顺便说一句,我已经解决了这个问题。谢谢! –