vendredi 4 décembre 2020

pytest cant find files while python can [duplicate]

I have a file structure like:

--app
    --src
        --__init__.py
        --module1.py
        --module2.py
    --tests
        --__init__.py
        --test1.py

A function in module1 calls a class in module2. The testing checks that function in module1. In module1.py if I import my class like from src.module2 import Passport PyTest works correctly, but trying to run module1 normally gives me the error ModuleNotFoundError: No module named 'src'. If I change the import to from module2 import Passport Python will run correctly but PyTest fails with the error: ModuleNotFoundError: No module named 'module2'

I've looked at lots of questions, but I can't seem to figure this out. Can anyone help?

Aucun commentaire:

Enregistrer un commentaire