Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest: ModuleNotFoundError: No module named 'src'

I'm starting to learn pytest and I want to integrate it with Travis later on. I've created my first tests and I can run them from PyCharm without any problem. But when I try to run pytest from Linux's terminal I get the following error:

Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.6/importlib/__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
test_prob.py:1: in <module>
    from src.agents import prob
E   ModuleNotFoundError: No module named 'src'

I've found some similar problems and solutions for them but none of them have worked for me. My project structure looks as follow

like image 854
cropyeee Avatar asked Sep 05 '25 03:09

cropyeee


1 Answers

I ran into the same issue, and my solution was to execute pytest as a module.

python -m pytest
like image 179
Mark Avatar answered Sep 07 '25 15:09

Mark