running into ModuleNotFoundError errors

Hi, I have a set of pytest unit tests, one of the functions include Google Cloud client library. If I run the unit tests as $pytest, they run just fine, however, I run it as coverage run -m pytest, it fails with the following error:

$ coverage run -m pytest
ImportError while loading conftest '/Users/myuser/my_app/tests/'.
tests/ in <module>
    from app.main import app
app/ in <module>
    from app.api import notification
app/api/ in <module>
    from app.api.k8s_util import K8sUtil
app/api/ in <module>
    from import container_v1
E   ModuleNotFoundError: No module named ''

@nedbat any ideas? I’m sure my configuration is missing something

thanks for your help

I might put import sys; print(sys.path) at the top of, run both ways, and see if there is a difference that would explain.

quick update, $pytest command is not printing anything and $coverage run -m pytest is printing paths that do not reflect the python virtual environment from where I’m running the test suite:


Instead of coverage run, try using python -m coverage run to ensure you are using the correct Python installation.

@nedbat wouldn’t that run just coverage but not pytest ? My apologies if my question doesn’t make much sense, I’m fairly new into Python.

When I run the suggested command, is not doing much:

$ python -m coverage run
Nothing to do.
Use 'coverage help' for help.
Full documentation is at

Sorry, meant to replace part of the command. You’d need python -m coverage run -m pytest

ahhh, python -m coverage run -m pytest command worked fine, does it mean when I run $coverage run -m pytest is using a different python configuration?