I have a very basic example of a Python package and a test which I'm trying to run with pytest
package
\--
__init__.py
spam.py
spam_test.py
__init__.py
is empty, spam.py
defines a single function func()
and spam_test.py
is:
import package.spam
def test_func():
assert(package.spam.func() == 5)
In the root directory I run py.test
and it all works, returning one passing test.
I thought that I could also structure things in this way:
package
\--
__init__.py
spam.py
tests
\--
spam_test.py
But now when I run py.test
in the root I get:
============================= test session starts ============================= platform win32 -- Python 3.6.0, pytest-3.0.5, py-1.4.32, pluggy-0.4.0 rootdir: C:\Users\MattUser\Documents\m_drive\notebooks\testing, inifile: collected 0 items / 1 errors =================================== ERRORS ==================================== _____________________ ERROR collecting tests/spam_test.py _____________________ ImportError while importing test module 'C:\Users\MattUser\Documents\m_drive\not ebooks\testing\tests\spam_test.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: tests\spam_test.py:1: in import package.spam E ModuleNotFoundError: No module named 'package' !!!!!!!!!!!!!!!!!!! Interrupted: 1 errors during collection !!!!!!!!!!!!!!!!!!! =========================== 1 error in 0.19 seconds ===========================
I've tried various things to no luck. What am I doing wrong??