A running Docker container with:
- A volume mounted to your source code (henceforth,
/code
) - SSH setup
- SSH enabled for the
root:password
creds and the root user allowed to login
Refer to docker-compose.yaml
and Dockerfile.dev
on how to achieve this.
- Preferences (CMD + ,) > Project Settings > Project Interpreter
- Click on the gear icon next to the "Project Interpreter" dropdown > Add
- Select "SSH Interpreter" > Host: localhost, Port: 9922, Username: root > Password: password > Interpreter: /usr/local/bin/python, Sync folders: Project Root -> /code, Disable "Automatically upload..."
- Confirm the changes and wait for PyCharm to update the indexes
- Install the Python extension
- Install the Remote - Containers extension
- Open the Command Pallette and type
Remote-Containers
, then select theAttach to Running Container...
and selecet the running docker container - VS Code will restart and reload
- On the
Explorer
sidebar, click theopen a folder
button and then enter/code
(this will be loaded from the remote container) - On the
Extensions
sidebar, select thePython
extension and install it on the container - When prompet on which interppreter to use, select
/usr/local/bin/python
- Open the Command Pallette and type
Python: Configure Tests
, then select theunittest
framework
- Code completion works
- Code navigation works
- Organize imports works
- Import suggestions/discovery works
- (VS Code) Tests (either classes or methods) will have a new line above their definitions, containing two actions:
Run Test | Debug Test
, and will be executed upon clicking on them - (PyCharm) Tests (either classes or methods) can be executed by placing the cursor on them and then using
Ctrl+Shift+R