Skip to content

Commit 10ace0f

Browse files
Updated logic
1 parent 98da04f commit 10ace0f

File tree

3 files changed

+45
-9
lines changed

3 files changed

+45
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
*.code-workspace
1111
!project.code-workspace
1212

13-
# Please, add your custom content below!
13+
# Specific to this blueprint
1414

1515
__pycache__/
1616
.pytest_cache/
1717
test-results/
1818
axe-reports/
1919
local.env
20+
21+
# Please, add your custom content below!

README.md

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This project is designed to provide a blueprint to allow for development teams t
1515
- [Configuration](#configuration)
1616
- [Getting Started](#getting-started)
1717
- [Utilities](#utilities)
18+
- [Using Environment Variables For Secrets](#using-environment-variables-for-secrets)
1819
- [Contributing](#contributing)
1920
- [Contacts](#contacts)
2021
- [Licence](#licence)
@@ -71,14 +72,42 @@ For additional reading and guidance on writing tests, we also recommend reviewin
7172

7273
## Utilities
7374

74-
This blueprint also provides the following utility classes, that can be used to aid in testing:
75+
This blueprint provides the following utility classes, that can be used to aid in testing:
7576

76-
|Utility|Description|
77-
|-------|-----------|
78-
|[Axe](./docs/utility-guides/Axe.md)|Accessibility scanning using axe-core.|
79-
|[Date Time Utility](./docs/utility-guides/DateTimeUtility.md)|Basic functionality for managing date/times.|
80-
|[NHSNumberTools](./docs/utility-guides/NHSNumberTools.md)|Basic tools for working with NHS numbers.|
81-
|[User Tools](./docs/utility-guides/UserTools.md)|Basic user management tool.|
77+
| Utility | Description |
78+
| ------------------------------------------------------------- | -------------------------------------------- |
79+
| [Axe](./docs/utility-guides/Axe.md) | Accessibility scanning using axe-core. |
80+
| [Date Time Utility](./docs/utility-guides/DateTimeUtility.md) | Basic functionality for managing date/times. |
81+
| [NHSNumberTools](./docs/utility-guides/NHSNumberTools.md) | Basic tools for working with NHS numbers. |
82+
| [User Tools](./docs/utility-guides/UserTools.md) | Basic user management tool. |
83+
84+
## Using Environment Variables For Secrets
85+
86+
This blueprint provides functionality for saving secret / sensitive values that you would not want present
87+
in the codebase, but require to execute tests locally (such as passwords or API keys). A local.env file can
88+
be generated by running the [following script](./setup_env_file.py):
89+
90+
```shell
91+
python ./setup_env_file.py
92+
```
93+
94+
This script file is design to be amended / updated as your project evolves, so as more sensitive values are required
95+
for executing tests, the list of keys provided can be updated so for subsequent runs of the script, all the expected
96+
keys are populated within the local.env file (which will need their values setting manually). The intent is that this
97+
script can be run to onboard new team members and provide a local file with all the variables they need to populate.
98+
99+
The local.env file (if present), is read at the start of any test session (via the [conftest.py file](./conftest.py))
100+
and any variables can be accessed by using the Python os library like so:
101+
102+
# Import the OS library
103+
import os
104+
105+
# Access environment variable
106+
os.getenv('<key_from_local.env>')
107+
108+
The local.env file is set in the [.gitignore file](./.gitignore), so by default it will not commit if amended.
109+
110+
> NOTE: You should never commit this file or any secrets in the codebase directly.
82111
83112
## Contributing
84113

conftest.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@
1515
@pytest.fixture(autouse=True, scope="session")
1616
def import_local_env_file() -> None:
1717
"""
18-
This fixture is used to import the local.env file into the test environment, if the file is present.
18+
This fixture is used to import the local.env file into the test environment (if the file is present),
19+
and will populate the environment variables prior to any tests running.
20+
If environment variables are set in a different way when running (e.g. via cli), this will
21+
prioritise those values over the local.env file.
22+
23+
NOTE: You should not use this logic to read a .env file in a pipeline or workflow to set sensitive values.
1924
"""
2025
if Path.is_file(LOCAL_ENV_PATH):
2126
load_dotenv(LOCAL_ENV_PATH, override=False)

0 commit comments

Comments
 (0)