This question is a follow up to this question that was answered by the user @wim.
I have the same structure
|
|-tests
| |----test_sum.py
|
|--script_to_test.py
|- pytest.ini
and the files script_to_test.py
def sum(a,b):
return a+b
pytest.ini
[pytest]
python_files = test_*
python_classes = *Tests
python_functions = test_*
test_sum.py
import script_to_test
def test_sum():
d=script_to_test.sum(6,5)
assert d==11
In this situation, pytest does not work since it fails to find the module script_to_test.py
I have read several solutions, some simple but incorrect, some complicated like installing modules, etc.
My solution is simple. Just add an empty file __init__.py
|
|-tests
| |----__init__.py
| |----test_sum.py
|
|--script_to_test.py
|- pytest.ini
and with this, pytest works.
Now my question is, is this solution correct, appropriate? and what is the influence of __init__.py
here?