I used easy_install to install pytest on a mac and started writing tests for a project with a file structure likes so:
repo/
repo/app.py
repo/settings.py
rep
I had the same problem. I fixed it by adding an empty __init__.py
file to my tests
directory.
As pointed out by Luiz Lezcano Arialdi, the correct solution is to install your package as an editable package.
Since I am using pipenv, I thought about adding to his answer a step-by-step how to install the current path as an edible with pipenv, allowing to run pytest without the need of any mangling code or loose files.
You will need to have the following minimal folder structure (documentation):
package/
package/
__init__.py
module.py
tests/
module_test.py
setup.py
setup.py most have the following minium code (documentation):
import setuptools
setuptools.setup(name='package', # Change to your package name
packages=setuptools.find_packages())
Then you just need to run pipenv install --dev -e .
and pipenv will install the current path as an editable package (the --dev flag is optional) (documentation).
Now you shoul be able to run pytest
without problems.