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
@@ -145,6 +145,10 @@ Steps:
145
145
AWS_PROFILE={your_profile}
146
146
IMMUNIZATION_ENV=local
147
147
```
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
+
```
148
152
149
153
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
150
154
```
@@ -161,6 +165,10 @@ Steps:
161
165
```
162
166
Test if environment variables have been loaded into shell: `echo $IMMUNIZATION_ENV`.
163
167
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
+
164
172
### Setting up the root level environment
165
173
The root-level virtual environment is primarily used for linting, as we create separate virtual environments for each folder that contains Lambda functions.
166
174
Steps:
@@ -176,20 +184,38 @@ The current team uses VS Code mainly. So this setup is targeted towards VS code.
176
184
177
185
### VS Code
178
186
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.
180
189
181
190
- Open the workspace `immunisation-fhir-api.code-workspace`.
182
191
- Copy `backend/.vscode/settings.json.default` to `backend/.vscode/settings.json`, or merge the contents with
183
192
your existing file.
193
+
- Similarly, copy or merge `backend/.vscode/launch.json.default` to `backend/.vscode/launch.json`.
184
194
185
195
VS Code will automatically use the `backend` environment when you're editing a file under `backend`.
186
196
187
197
Depending on your existing setup VS Code might automatically choose the wrong virtualenvs. Change it
188
198
with `Python: Select Interpreter`.
189
199
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).
191
209
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:
0 commit comments