Skip to content

Commit 52f204b

Browse files
Moving generic pytest fixtures to conftest (#52)
<!-- markdownlint-disable-next-line first-line-heading --> ## Description <!-- Describe your changes in detail. --> Moving generic pytest fixtures into conftest.py ## Context <!-- Why is this change required? What problem does it solve? --> Reduces the amount of repeat code ## Type of changes <!-- What types of changes does your code introduce? Put an `x` in all the boxes that apply. --> - [x] Refactoring (non-breaking change) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would change existing functionality) - [ ] Bug fix (non-breaking change which fixes an issue) ## Checklist <!-- Go over all the following points, and put an `x` in all the boxes that apply. --> - [x] I am familiar with the [contributing guidelines](https://github.com/nhs-england-tools/playwright-python-blueprint/blob/main/CONTRIBUTING.md) - [x] I have followed the code style of the project - [ ] I have added tests to cover my changes (where appropriate) - [ ] I have updated the documentation accordingly - [ ] This PR is a result of pair or mob programming --- ## Sensitive Information Declaration To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including [PII (Personal Identifiable Information) / PID (Personal Identifiable Data)](https://digital.nhs.uk/data-and-information/keeping-data-safe-and-benefitting-the-public) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter. - [x] I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.
1 parent 367184e commit 52f204b

13 files changed

+26
-70
lines changed

conftest.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88
import os
99
from dotenv import load_dotenv
1010
from pathlib import Path
11+
from utils.load_properties_file import PropertiesFile
1112

12-
LOCAL_ENV_PATH = Path(os.getcwd()) / 'local.env'
13+
LOCAL_ENV_PATH = Path(os.getcwd()) / "local.env"
1314

1415

1516
@pytest.fixture(autouse=True, scope="session")
@@ -24,3 +25,13 @@ def import_local_env_file() -> None:
2425
"""
2526
if Path.is_file(LOCAL_ENV_PATH):
2627
load_dotenv(LOCAL_ENV_PATH, override=False)
28+
29+
30+
@pytest.fixture
31+
def smokescreen_properties() -> dict:
32+
return PropertiesFile().get_smokescreen_properties()
33+
34+
35+
@pytest.fixture
36+
def general_properties() -> dict:
37+
return PropertiesFile().get_general_properties()

setup_env_file.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@
1111
import os
1212
from pathlib import Path
1313

14-
REQUIRED_KEYS = ["USER_PASS"]
15-
DEFAULT_LOCAL_ENV_PATH = Path(os.getcwd()) / 'local.env'
14+
REQUIRED_KEYS = ["BCSS_PASS", "ORACLE_USERNAME", "ORACLE_DB", "ORACLE_PASS"]
15+
DEFAULT_LOCAL_ENV_PATH = Path(os.getcwd()) / "local.env"
16+
1617

1718
def create_env_file():
1819
"""
1920
Create a local.env file with the required keys.
2021
"""
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")
22+
with open(DEFAULT_LOCAL_ENV_PATH, "w") as f:
23+
f.write(
24+
"# Use this file to populate secrets without committing them to the codebase (as this file is set in .gitignore).\n"
25+
)
26+
f.write(
27+
"# To retrieve values as part of your tests, use os.getenv('VARIABLE_NAME').\n"
28+
)
29+
f.write(
30+
"# Note: When running in a pipeline or workflow, you should pass these variables in at runtime.\n\n"
31+
)
2532
for key in REQUIRED_KEYS:
26-
f.write(f'{key}=\n')
33+
f.write(f"{key}=\n")
2734

2835

2936
if __name__ == "__main__":

tests/smokescreen/test_compartment_1.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
from pages.call_and_recall.generate_invitations_page import GenerateInvitationsPage
1111
from playwright.sync_api import Page
1212
from utils.batch_processing import batch_processing
13-
from utils.load_properties_file import PropertiesFile
14-
15-
16-
@pytest.fixture
17-
def smokescreen_properties() -> dict:
18-
return PropertiesFile().get_smokescreen_properties()
1913

2014

2115
@pytest.mark.smoke

tests/smokescreen/test_compartment_2.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
from utils.fit_kit_generation import create_fit_id_df
1111
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
1212
from utils.user_tools import UserTools
13-
from utils.load_properties_file import PropertiesFile
14-
15-
16-
@pytest.fixture
17-
def smokescreen_properties() -> dict:
18-
return PropertiesFile().get_smokescreen_properties()
1913

2014

2115
@pytest.mark.vpn_required

tests/smokescreen/test_compartment_3.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@
1010
execute_fit_kit_stored_procedures,
1111
)
1212
from utils.user_tools import UserTools
13-
from utils.load_properties_file import PropertiesFile
14-
15-
16-
@pytest.fixture
17-
def smokescreen_properties() -> dict:
18-
return PropertiesFile().get_smokescreen_properties()
1913

2014

2115
@pytest.mark.vpn_required

tests/smokescreen/test_compartment_4.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
EpisodeEventsAndNotesPage,
2525
)
2626
from utils.user_tools import UserTools
27-
from utils.load_properties_file import PropertiesFile
2827
from utils.calendar_picker import CalendarPicker
2928
from utils.batch_processing import batch_processing
3029
from datetime import datetime
@@ -33,11 +32,6 @@
3332
import logging
3433

3534

36-
@pytest.fixture
37-
def smokescreen_properties() -> dict:
38-
return PropertiesFile().get_smokescreen_properties()
39-
40-
4135
@pytest.mark.vpn_required
4236
@pytest.mark.smokescreen
4337
@pytest.mark.compartment4

tests/smokescreen/test_compartment_5.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,13 @@
4949
)
5050

5151
from utils.user_tools import UserTools
52-
from utils.load_properties_file import PropertiesFile
5352
from utils.screening_subject_page_searcher import verify_subject_event_status_by_nhs_no
5453
from utils.calendar_picker import CalendarPicker
5554
from utils.oracle.oracle_specific_functions import get_subjects_with_booked_appointments
5655
from datetime import datetime, timedelta
5756
import logging
5857

5958

60-
@pytest.fixture
61-
def smokescreen_properties() -> dict:
62-
return PropertiesFile().get_smokescreen_properties()
63-
64-
6559
@pytest.mark.vpn_required
6660
@pytest.mark.smokescreen
6761
@pytest.mark.compartment5

tests/test_call_and_recall_page.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
from pages.call_and_recall.invitations_plans_page import InvitationsPlansPage
1212
from pages.call_and_recall.create_a_plan_page import CreateAPlanPage
1313
from utils.user_tools import UserTools
14-
from utils.load_properties_file import PropertiesFile
15-
16-
17-
@pytest.fixture
18-
def general_properties() -> dict:
19-
return PropertiesFile().get_general_properties()
2014

2115

2216
@pytest.fixture(scope="function", autouse=True)

tests/test_fit_test_kits_page.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
from pages.fit_test_kits.manage_qc_products_page import ManageQCProductsPage
1616
from pages.fit_test_kits.maintain_analysers_page import MaintainAnalysersPage
1717
from utils.user_tools import UserTools
18-
from utils.load_properties_file import PropertiesFile
19-
20-
21-
@pytest.fixture
22-
def general_properties() -> dict:
23-
return PropertiesFile().get_general_properties()
2418

2519

2620
@pytest.fixture(scope="function", autouse=True)

tests/test_organisations_page.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,6 @@
33
from pages.base_page import BasePage
44
from pages.organisations.organisations_page import OrganisationsPage
55
from utils.user_tools import UserTools
6-
from utils.load_properties_file import PropertiesFile
7-
8-
9-
@pytest.fixture
10-
def general_properties() -> dict:
11-
return PropertiesFile().get_general_properties()
126

137

148
@pytest.fixture(scope="function", autouse=True)

0 commit comments

Comments
 (0)