You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+29-3Lines changed: 29 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,6 +147,10 @@ Steps:
147
147
AWS_PROFILE={your_profile}
148
148
IMMUNIZATION_ENV=local
149
149
```
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
+
```
150
154
151
155
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
152
156
```
@@ -163,6 +167,10 @@ Steps:
163
167
```
164
168
Test if environment variables have been loaded into shell: `echo $IMMUNIZATION_ENV`.
165
169
170
+
#### Running Unit Tests from the Command Line
171
+
172
+
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.
173
+
166
174
### Setting up the root level environment
167
175
The root-level virtual environment is primarily used for linting, as we create separate virtual environments for each folder that contains Lambda functions.
168
176
Steps:
@@ -178,20 +186,38 @@ The current team uses VS Code mainly. So this setup is targeted towards VS code.
178
186
179
187
### VS Code
180
188
181
-
The project must be opened as a multi-root workspace for VS Code to know that `backend` has its own environment.
189
+
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.
190
+
This example is for `backend`; substitute another lambda name in where applicable.
182
191
183
192
- Open the workspace `immunisation-fhir-api.code-workspace`.
184
193
- Copy `backend/.vscode/settings.json.default` to `backend/.vscode/settings.json`, or merge the contents with
185
194
your existing file.
195
+
- Similarly, copy or merge `backend/.vscode/launch.json.default` to `backend/.vscode/launch.json`.
186
196
187
197
VS Code will automatically use the `backend` environment when you're editing a file under `backend`.
188
198
189
199
Depending on your existing setup VS Code might automatically choose the wrong virtualenvs. Change it
190
200
with `Python: Select Interpreter`.
191
201
192
-
The root (`immunisation-fhir-api`) should point to `/mnt/d/Source/immunisation-fhir-api/.venv/bin/python`.
202
+
The root (`immunisation-fhir-api`) should point to the root `.venv`, e.g. `/mnt/d/Source/immunisation-fhir-api/.venv/bin/python`.
203
+
204
+
Meanwhile, `backend` should be pointing at (e.g.) `/mnt/d/Source/immunisation-fhir-api/backend/.venv/bin/python`
205
+
206
+
#### Running Unit Tests
207
+
208
+
Note that unit tests can be run from the command line without VSCode configuration.
209
+
210
+
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).
193
211
194
-
`backend` should be pointing at `/mnt/d/Source/immunisation-fhir-api/backend/.venv/bin/python`
212
+
**NOTE:** In order to run unit test suites, you may need to manually switch to the correct virtual environment each time you wish to
213
+
run a different set of tests. To do this:
214
+
- Show and Run Commands (Ctrl-Shift-P on Windows)
215
+
- Python: Create Environment
216
+
- Venv
217
+
- Select the `.venv` named for the test suite you wish to run, e.g. `backend`
218
+
- Use Existing
219
+
- VSCode should now display a toast saying that the following environment is selected:
0 commit comments