Skip to content

Commit 1f297d4

Browse files
initial work
1 parent 6c57f94 commit 1f297d4

File tree

5 files changed

+53
-2
lines changed

5 files changed

+53
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ __pycache__/
1616
.pytest_cache/
1717
test-results/
1818
axe-reports/
19+
local.env

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ To utilise the blueprint code, you will need to have the following installed:
3333

3434
- [Python](https://www.python.org/downloads/) 3.12 or greater
3535

36-
> NOTE: There are currently known issues with Python 3.13 and Playwright, so if you encounter issues running this project whilst using Python 3.13 it is recommended to downgrade to Python 3.12 in the interim.
37-
3836
Whilst not required to get started, you may also want to [configure a Python virtual environment for your project](https://docs.python.org/3/library/venv.html) before proceeding with
3937
the configuration. If you are using an IDE such as Visual Studio Code or PyCharm, you will normally be prompted to do this automatically.
4038

conftest.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
This is a conftest.py file for pytest, which is used to set up fixtures and hooks for testing.
3+
This file is used to define fixtures that can be used across multiple test files.
4+
It is also used to define hooks that can be used to modify the behavior of pytest.
5+
"""
6+
7+
import pytest
8+
import os
9+
from dotenv import load_dotenv
10+
from pathlib import Path
11+
12+
LOCAL_ENV_PATH = Path(os.getcwd()) / 'local.env'
13+
14+
15+
@pytest.fixture(autouse=True, scope="session")
16+
def import_local_env_file() -> None:
17+
"""
18+
This fixture is used to import the local.env file into the test environment, if the file is present.
19+
"""
20+
if Path.is_file(LOCAL_ENV_PATH):
21+
load_dotenv(LOCAL_ENV_PATH, override=False)

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ pytest-playwright>=0.5.1
22
pytest-html>=4.1.1
33
pytest-json-report>=1.5.0
44
pytest-playwright-axe>=4.10.3
5+
python-dotenv>=1.1.0

setup_env_file.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
This script creates a local.env file that can be used to populate secrets such as passwords or API keys
3+
locally. This is useful for local development and testing, as it allows you to keep sensitive information
4+
out of your codebase.
5+
6+
This is designed to be generated when setting up this project, so if new variables are required, these
7+
should be added to the REQUIRED_KEYS list below to automatically populate the local.env file with the
8+
keys required to run this project.
9+
"""
10+
11+
import os
12+
from pathlib import Path
13+
14+
REQUIRED_KEYS = ["USER_PASS"]
15+
DEFAULT_LOCAL_ENV_PATH = Path(os.getcwd()) / 'local.env'
16+
17+
def create_env_file():
18+
"""
19+
Create a .env file with the required keys.
20+
"""
21+
with open(DEFAULT_LOCAL_ENV_PATH, 'w') as f:
22+
f.write("# Use this file to populate secrets without committing them to the codebase (as this file is set in .gitignore).\n")
23+
f.write("# To retrieve values as part of your tests, use os.getenv('VARIABLE_NAME').\n")
24+
f.write("# Note: When running in a pipeline or workflow, you should pass these variables in at runtime.\n\n")
25+
for key in REQUIRED_KEYS:
26+
f.write(f'{key}=\n')
27+
28+
29+
if __name__ == "__main__":
30+
create_env_file()

0 commit comments

Comments
 (0)