The closest thing I have found to my problem is this question, ImportError shows up with py.test but no when running the app, except in my case I am getting an ImportError from an external library I have installed with pip in my virtual environment.
The error I get is:
==================================== ERRORS ====================================
________________ ERROR collecting scraper/tests/test_scraper.py ________________
scraper/tests/test_scraper.py:1: in <module>
from scraper import scraper
scraper/scraper.py:3: in <module>
from bs4 import BeautifulSoup
E ImportError: No module named 'bs4'
What is strange is that I can run scraper.py just fine with no errors. Plus, bs4 is clearly installed, as demonstrated with I call pip list:
$pip list
beautifulsoup4 (4.4.1)
bs4 (0.0.1)
pip (8.1.2)
py (1.4.31)
pytest (2.9.2)
setuptools (23.0.0)
wheel (0.29.0)
I have tried the solutions suggested from previous answers: setting the PYTHONPATH to the directory of the project and creating a conftest.py file in said directory.
$ pwd
/Users/kgero/Documents/Projects/PoetryEngine
$ echo $PYTHONPATH
/Users/kgero/Documents/Projects/PoetryEngine
$ ls
__pycache__ features poems venv
conftest.py main.py scraper
So why can't pytest successfully find the module?