{"id":945,"hash":"78b17c579d22d8982a0066d3f857f6dd27fc534b9fd4b156f7ee60d917ff9ad9","pattern":"Getting error ImportMismatchError while running py.test","full_message":"When I am running tests locally its working fine, but after creating the docker and running inside the container I am getting below error.\n\n    /usr/local/lib/python3.5/site-packages/_pytest/config.py:325: in _getconftestmodules\n    return self._path2confmods[path]\nE   KeyError: local('/apis/db/tests')\n\nDuring handling of the above exception, another exception occurred:\n/usr/local/lib/python3.5/site-packages/_pytest/config.py:356: in _importconftest\n    return self._conftestpath2mod[conftestpath]\nE   KeyError: local('/apis/db/tests/conftest.py')\n\nDuring handling of the above exception, another exception occurred:\n/usr/local/lib/python3.5/site-packages/_pytest/config.py:362: in _importconftest\n    mod = conftestpath.pyimport()\n/usr/local/lib/python3.5/site-packages/py/_path/local.py:680: in pyimport\n    raise self.ImportMismatchError(modname, modfile, self)\n\n_pytest.config.ConftestImportFailure: ImportMismatchError('conftest', '/projects/my_project/db/tests/conftest.py', local('/apis/db/tests/conftest.py'))\n\n/apis - its the WORKDIR in Dockerfile.","ecosystem":"pypi","package_name":"docker","package_version":null,"solution":"I have fixed it by removing all __pycache__ pkg under test/ directory, the issue was when I was creating docker image its picking all my __pycache__ and *.pyc files too, at the time when test are running its using my local machine path instead of the path in docker container.\n\nConclusion: Clear your *.pyc and __pycache__ files before creating a docker image.","confidence":0.95,"source":"stackoverflow","source_url":"https://stackoverflow.com/questions/44067609/getting-error-importmismatcherror-while-running-py-test","votes":92,"created_at":"2026-04-19T04:52:04.240368+00:00","updated_at":"2026-04-19T04:52:04.240368+00:00"}