當我在本地運行測試時它的工作正常,但是在創建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的主目錄中,順便說一句,我已經解決了這個問題。謝謝! –