0

I have a directory structure like this:

/myapp
  __init__.py
  /app
     /main.py
  /test
     /test_main.py

__init__py (/myapp/__init__py) has imports defined as:

from flask import Flask
app = Flask(__name__)

# some code  

test_main.py(/myapp/test/test_main.py) has imports:

import unittest
from myapp import app

# Testing code

When I try to test test_main.pyc (pytest test_main.py), it throws an ImportError: No module named myapp

I'm unable to find out why it is unable to import.

user2430771
  • 1,326
  • 4
  • 17
  • 33
  • This may be relevant, http://stackoverflow.com/a/24266885/5781248 – J.J. Hakala Jan 25 '16 at 02:18
  • When you run `python test_main.py`, your `PYTHONPATH` includes system locations, and `myapp/test`. This does **not** include `myapp`, which is why you can't import from it. You can solve this problem by using relative imports, adjusting your `PYTHONPATH`, or using e.g. the `unittest` CLI (as suggested by @J.J.Hakala) which will do the latter for you. – Thomas Orozco Jan 25 '16 at 02:35

0 Answers0