Py.test No module named *

zsljulius picture zsljulius · Jan 8, 2014 · Viewed 45.9k times · Source

I have a folder structure like this

App
--App
  --app.py       
--Docs
--Tests
  --test_app.py

In my test_app.py file, I have a line to import my app module. When I run py.test on the root folder, I get this error about no module named app. How should I configure this?

Answer

jamesc picture jamesc · Apr 22, 2017

Working with Python 3 and getting the same error on a similar project layout, I solved it by adding an __init__ file to my tests module.

$ touch tests/__init__.py

I'm not great at packaging and importing, but I think that this helps pytest work out where the target App module is located.