Skip to content

Commit 3c3fb85

Browse files
committed
README and launch.json.default
1 parent 20c3a7f commit 3c3fb85

File tree

2 files changed

+54
-3
lines changed

2 files changed

+54
-3
lines changed

README.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ Steps:
147147
AWS_PROFILE={your_profile}
148148
IMMUNIZATION_ENV=local
149149
```
150+
For unit tests to run successfully, you may also need to add an environment variable for PYTHONPATH. This should be:
151+
```
152+
PYTHONPATH=src:tests
153+
```
150154
151155
4. Configure `direnv` by creating a `.envrc` file in the backend folder. This points direnv to the `.venv` created by poetry and loads env variables specified in the `.env` file
152156
```
@@ -178,20 +182,34 @@ The current team uses VS Code mainly. So this setup is targeted towards VS code.
178182
179183
### VS Code
180184
181-
The project must be opened as a multi-root workspace for VS Code to know that `backend` has its own environment.
185+
The project must be opened as a multi-root workspace for VS Code to know that specific lambdas (e.g. `backend`) have their own environment.
186+
This example is for `backend`; substitute another lambda name in where applicable.
182187
183188
- Open the workspace `immunisation-fhir-api.code-workspace`.
184189
- Copy `backend/.vscode/settings.json.default` to `backend/.vscode/settings.json`, or merge the contents with
185190
your existing file.
191+
- Similarly, copy or merge `backend/.vscode/launch.json.default` to `backend/.vscode/launch.json`.
186192
187193
VS Code will automatically use the `backend` environment when you're editing a file under `backend`.
188194
189195
Depending on your existing setup VS Code might automatically choose the wrong virtualenvs. Change it
190196
with `Python: Select Interpreter`.
191197
192-
The root (`immunisation-fhir-api`) should point to `/mnt/d/Source/immunisation-fhir-api/.venv/bin/python`.
198+
The root (`immunisation-fhir-api`) should point to the root .venv, `/mnt/d/Source/immunisation-fhir-api/.venv/bin/python`.
199+
200+
Meanwhile, `backend` should be pointing at `/mnt/d/Source/immunisation-fhir-api/backend/.venv/bin/python`
201+
202+
#### Running Unit Tests
203+
204+
In order that VSCode can resolve modules in unit tests, it needs the PYTHONPATH. This should be setup in `backend/.vscode/launch.json` (see above).
193205
194-
`backend` should be pointing at `/mnt/d/Source/immunisation-fhir-api/backend/.venv/bin/python`
206+
*NOTE:* In order to run unit test suites, you may need to manually switch to the correct virtual environment each time you wish to
207+
run a different set of tests. To do this:
208+
- Show and Run Commands (Ctrl-Shift-P on Windows)
209+
-> Python: Create Environment
210+
-> Venv
211+
-> Select the venv named for the test suite you wish to run, e.g. `backend`
212+
-> Use Existing
195213
196214
### IntelliJ
197215
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "File",
6+
"type": "debugpy",
7+
"request": "launch",
8+
"module": "unittest",
9+
"args": [
10+
"${fileBasenameNoExtension}" // Run tests in the current file
11+
],
12+
"console": "integratedTerminal",
13+
"env": {
14+
"PYTHONPATH": "${workspaceFolder}:${workspaceFolder}/src:${workspaceFolder}/tests" // Add root, src, and tests
15+
}
16+
},
17+
{
18+
"name": "Here",
19+
"type": "debugpy",
20+
"request": "launch",
21+
"module": "unittest",
22+
"args": [
23+
"-k",
24+
"${selectedText}" // Run the test method or class under the cursor
25+
],
26+
"console": "integratedTerminal",
27+
"justMyCode": true,
28+
"env": {
29+
"PYTHONPATH": "${workspaceFolder}:${workspaceFolder}/src:${workspaceFolder}/tests" // Add root, src, and tests
30+
}
31+
}
32+
]
33+
}

0 commit comments

Comments
 (0)