I wanted to get advice on the best way to setup a simple app with pytest.
I can run pytest fine on a single file but I wanted to bootstrap a Python app using:
mypkg/
__init__.py
app.py
tests/
__init__.py
test_app.py
But when I run pytest I get an error:
NameError: name 'func' is not defined
mypkg/__init__.py file
# content of __init__.py
# Empty init file
mypkg/app.py file
# content of app.py
class mypkg:
def func(x):
return x + 1
tests/__init__.py file
# content of __init__.py
# Empty init file
tests/test_app.py file
# content of test_app.py
import pytest
import mypkg
def test_answer():
assert func(4) == 5
I'm using Python 3.5.
Do I need a setup.py and if I try calling mypkg.func(4) instead I get an AttributeError: modulemypkghas no attribute 'func'.
Any help is much appreciated.