I have the following project structure in Pycharm -
project/
src/
main.py
config/
__init__.py
settings.py
package1/
__init__.py
client.py # Imports settings from config using -> from ..config import settings
tests/
__init__.py
test.py
So here my client.py imports settings -
from ..config import settings
main.py imports client -
from package1.client import clientFunction # ClientFunction is the method defined inside client.py
I use pytest to run the tests. So now when i run the pytest configuration, in my test cases i import main. I dont see any errors in my code but when the tests run it says -
from ..config import settings
E ValueError: attempted relative import beyond top-level package
How can i fix this? Seems like pytest is taking a different path to execute the tests and hence the relative imports are going beyond the top level.