Pytest won't import folders correctly

53 views Asked by At

I am trying to write unit tests using pytest for a file. My directory structure looks like this:

--app
    --app.py
    --src
        --helpers
            --math
                --__init__.py
                --file1.py
                --file2.py

    --tests
        --unit
            --test_file1.py
        --functional
    --conftest.py

In test_file1.py, I have the followimg import statement: from src.helpers.math.file1 import mainClass

When I call pytest on test_file1.py, it insists ModuleNotFoundError: No module named helpers. I don't understand why it can't find helpers.

I have tried adding an __init__.py file to src and helpers; I've tried changing how I call the import statement to only say src,helpers.math and other combinations; but no matter what I do, pytest can't seem to find this module and I don't understand why. Another pytest file that is testing a file with only functions, no classes, is working fine so I'm convinced I'm doing something wrong with classes.

0

There are 0 answers