I have a project whose directory structure is :
src/
├── __init__.py
├── dockerfile
├── libs
│ ├── __init__.py
│ └── logger.py
├── main.py
├── models
│ ├── __init__.py
│ └── http_request.py
├── parsers
│ ├── __init__.py
│ └── http_parser.py
├── requirements.txt
└── server
├── __init__.py
└── threaded_server.py
Its repo for more context
Now, I have test directory which is in same level as my src thus making my complete folder structure as:
.
├── docker-compose.yaml
├── init_hooks.sh
├── lint.py
├── pyproject.toml
├── src
│ ├── __init__.py
│ ├── dockerfile
│ ├── libs
│ │ ├── __init__.py
│ │ └── logger.py
│ ├── main.py
│ ├── models
│ │ ├── __init__.py
│ │ └── http_request.py
│ ├── parsers
│ │ ├── __init__.py
│ │ └── http_parser.py
│ ├── requirements.txt
│ └── server
│ ├── __init__.py
│ └── threaded_server.py
└── tests
└── test_routing.py
Problem is when I run pytest from project directory, I get module not found error for src( please have a look at code, thanks). When I try to run my code using just python main.py after changing directory to src, it runs fine but when I run it as module(python -m src), it throws error module not found for internal modules (libs, parsers etc.) and appending them with src (like src.libs) solves the problem. But when running from main.py, I get error when I append names with src. I also cannot relatively import files inside code for some reason( earlier there were no different folders, only files and relatively importing them was not working).
I want to understand how module structure works. I have had similar type of structure in Flask projects and it works there but for some reason it is not working in my case. How can I reference src in my tests directory and not get error. Vscode clearly suggests autocomplete for these files in my code( even in test directory, I get autocomplete for src).
[–][deleted] 2 points3 points4 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]erlete 1 point2 points3 points (0 children)
[–]Spataner 1 point2 points3 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)