I have a directory structure as recommended by the pytest good integration practices guide, which looks like this:
.
src/
mypkg/
__init__.py
mypkg.py
tests/
__init__.py
test_mypkg.py
The __init__.py files are both empty, and the other files are as follows:
mypkg.pydef foo(x):
"""
Show x.
>>> foo(5)
x is 5
>>> foo("hello")
x is hello
"""
return "x is {0}".format(x)
test.pyfrom mypkg import *
def test_foo():
assert foo(5) == "x is 5"
When I run pytest from the root directory I get:
tests\test_foo.py:1: in <module>
from mypkg import *
E ModuleNotFoundError: No module named 'mypkg'
What is the recommended way of setting this up?
I am no pytest specialist but this looks like a mission for conftest.py, conftest allow one to load tests from module / package / shared fixtures and more...
See this page for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With