Skip to content

Commit 5db7a30

Browse files
JamesW1-NHSmfjarvis
authored andcommitted
VED-727 README for VSCode Configuration (#742)
* local_id * vaccine_type * pre-check body * temp. revert * _log_data_from_body * _log_data_from_body II * supplier * cleanup, add tests * smell * log partial detail where available * LF * review cleanup * README and launch.json.default * clean * CLI * grammar
1 parent 7bf18e6 commit 5db7a30

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

README.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ Steps:
145145
AWS_PROFILE={your_profile}
146146
IMMUNIZATION_ENV=local
147147
```
148+
For unit tests to run successfully, you may also need to add an environment variable for PYTHONPATH. This should be:
149+
```
150+
PYTHONPATH=src:tests
151+
```
148152
149153
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
150154
```
@@ -161,6 +165,10 @@ Steps:
161165
```
162166
Test if environment variables have been loaded into shell: `echo $IMMUNIZATION_ENV`.
163167
168+
#### Running Unit Tests from the Command Line
169+
170+
It is not necessary to activate the virtual environment (using `source .venv/bin/activate`) before running a unit test suite from the command line; `direnv` will pick up the correct configurations for us. Run `pip list` to verify that the expected packages are installed. You should for example see that `recordprocessor` is specifically running `moto` v4, regardless of which if any `.venv` is active.
171+
164172
### Setting up the root level environment
165173
The root-level virtual environment is primarily used for linting, as we create separate virtual environments for each folder that contains Lambda functions.
166174
Steps:
@@ -176,20 +184,38 @@ The current team uses VS Code mainly. So this setup is targeted towards VS code.
176184
177185
### VS Code
178186
179-
The project must be opened as a multi-root workspace for VS Code to know that `backend` has its own environment.
187+
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.
188+
This example is for `backend`; substitute another lambda name in where applicable.
180189
181190
- Open the workspace `immunisation-fhir-api.code-workspace`.
182191
- Copy `backend/.vscode/settings.json.default` to `backend/.vscode/settings.json`, or merge the contents with
183192
your existing file.
193+
- Similarly, copy or merge `backend/.vscode/launch.json.default` to `backend/.vscode/launch.json`.
184194
185195
VS Code will automatically use the `backend` environment when you're editing a file under `backend`.
186196
187197
Depending on your existing setup VS Code might automatically choose the wrong virtualenvs. Change it
188198
with `Python: Select Interpreter`.
189199
190-
The root (`immunisation-fhir-api`) should point to `/mnt/d/Source/immunisation-fhir-api/.venv/bin/python`.
200+
The root (`immunisation-fhir-api`) should point to the root `.venv`, e.g. `/mnt/d/Source/immunisation-fhir-api/.venv/bin/python`.
201+
202+
Meanwhile, `backend` should be pointing at (e.g.) `/mnt/d/Source/immunisation-fhir-api/backend/.venv/bin/python`
203+
204+
#### Running Unit Tests
205+
206+
Note that unit tests can be run from the command line without VSCode configuration.
207+
208+
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).
191209
192-
`backend` should be pointing at `/mnt/d/Source/immunisation-fhir-api/backend/.venv/bin/python`
210+
**NOTE:** In order to run unit test suites, you may need to manually switch to the correct virtual environment each time you wish to
211+
run a different set of tests. To do this:
212+
- Show and Run Commands (Ctrl-Shift-P on Windows)
213+
- Python: Create Environment
214+
- Venv
215+
- Select the `.venv` named for the test suite you wish to run, e.g. `backend`
216+
- Use Existing
217+
- VSCode should now display a toast saying that the following environment is selected:
218+
- (e.g.) `/mnt/d/Source/immunisation-fhir-api/backend/.venv/bin/python`
193219
194220
### IntelliJ
195221
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)