Getting error ImportMismatchError while running py.test

When I am running tests locally its working fine, but after creating the docker and running inside the container I am getting below error.

    /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 – its the WORKDIR in Dockerfile.

  • cant add cAdvisor application metric to Grafana
  • How can I use the base image to create my own without the dependency?
  • How do I forward my Docker IP to the rest of the network?
  • Service name for Docker Compose remote interpreter in PyCharm 5.1 Beta 2
  • Docker container with Python Web App - Connect to Postgres on Host machine (OSX)
  • View files in docker container
  • CI & Docker-in-a-Docker
  • Docker automated build results in Unexpected failure
  • Unable to run Tomcat 7 as service inside container on CoreOS
  • How to deploy AngularJS app using nginx + docker to Elastic Beanstalk?
  • how to open rails app code from Discourse docker container?
  • Can not Start Rancher Agent in Docker
  • One Solution collect form web for “Getting error ImportMismatchError while running py.test”

    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.

    Conclusion: Clear your *.pyc and pycache files before creating a docker image.

    HTH

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.