I have a project named unit_testing
with 2 subfolders named src/
and tests/
. In src
there is a file called my_functions.py and in tests I have a file called test_my_functions.py.
This is the code in my_functions.py
def adding_pos(a, b, c):
if a < 0 or b < 0 or c < 0:
output = f'function needs positive numbers'
else:
output = a + b + c
return output
This is the code in test_my_functions.py
# import libs
import pytest
from src.my_functions import adding_pos
# %% test
class TestAddingPos(object):
def test_adding(self):
assert adding_pos(2, 5, 6) == 13
def test_adding_neg(self):
assert adding_pos(-1, 2, 3) == 'function needs positive numbers'
In the CLI, if I go to the test folder and then run pytest, I keep getting a ModuleNotfoundError
saying the src
module can not be found. I don' understand why because in test_my_functions.py I import functions from src.my_functions and this works.
Why does this not work?