I'm having more trouble than I'd like to admit to structure a simple project in Python to develop using Visual Studio Code.
How should I structure in my file system a project that is a simple Python package with a few modules? Just a bunch of *.py files together. My requisites are:
- I must be able to step debug it in vscode.
- It has a bunch of unit tests using pytest.
- I can select to debug a specific test from vscode tab and it must stop in breakpoints.
- pylint must not show any false positives.
- The test files must be in a different directory of the main module files.
- I must be able to run all the tests from the console.
- The module is executed inside a virtual environment using python standard lib module venv
- The code will use type hints
I may use another linter, even another test framework.
Nothing fancy, but I'm really having trouble to get it right. I want to know:
- How should I organize my subdirectory: a folder with the main files and a sibling folder with the tests? Or a subfolder with the code and a subsubfolder with the tests?
- Which dirs must have a init.py file?
- How the tests should import the files from the module? Should I use relative imports?
- Should I create a
pytest.ini
file?
- Should I create a
.env
file?
- What's the content of my
launch.json
the debugger file config in vscode?
Some years later, I now think that the best option is to use Poetry package and environment manager. You must start your projects just using poetry new <my-package>
that it will create the structure for you.
Now everything just works.