Skip to content

Commit 2b470d3

Browse files
Changed util to account for environment used
1 parent ddd2e92 commit 2b470d3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

tests/regression/subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from datetime import datetime, timedelta
22
import pandas as pd
33
import pytest
4+
from _pytest.fixtures import FixtureRequest
45
import logging
56
from playwright.sync_api import Page
67
from classes.subject import Subject
@@ -62,7 +63,9 @@
6263
from utils.user_tools import UserTools
6364

6465

65-
def test_setup_subjects_as_a99(page: Page, subjects_to_run_for: int) -> None:
66+
def test_setup_subjects_as_a99(
67+
page: Page, subjects_to_run_for: int, request: FixtureRequest
68+
) -> None:
6669
"""
6770
Scenario Outline: Set up 10 subjects to be at status A99
6871
"""
@@ -76,8 +79,9 @@ def test_setup_subjects_as_a99(page: Page, subjects_to_run_for: int) -> None:
7679
if not param_29_set_correctly:
7780
set_org_parameter_value(29, "20:00", "23162")
7881

82+
base_url = request.config.getoption("--base-url")
7983
if not has_test_run_today(
80-
"subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup"
84+
"subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup", base_url # type: ignore
8185
):
8286
setup_appointments(page)
8387
page = page.context.new_page()
@@ -106,7 +110,9 @@ def test_setup_subjects_as_a99(page: Page, subjects_to_run_for: int) -> None:
106110
LogoutPage(page).log_out()
107111

108112

109-
def test_setup_subjects_as_a259(page: Page, subjects_to_run_for: int) -> None:
113+
def test_setup_subjects_as_a259(
114+
page: Page, subjects_to_run_for: int, request: FixtureRequest
115+
) -> None:
110116
"""
111117
Set up 10 subjects to have new Colonoscopy datasets in episodes started within in the last 4 years
112118
"""
@@ -120,8 +126,9 @@ def test_setup_subjects_as_a259(page: Page, subjects_to_run_for: int) -> None:
120126
if not param_29_set_correctly:
121127
set_org_parameter_value(29, "20:00", "23162")
122128

129+
base_url = request.config.getoption("--base-url")
123130
if not has_test_run_today(
124-
"subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup"
131+
"subject/episodes/datasets/investigation/endoscopy/polypcategories/test_setup", base_url # type: ignore
125132
):
126133
setup_appointments(page)
127134
page = page.context.new_page()

utils/last_test_run.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import os
22
import json
33
from datetime import date
4-
from typing import Dict, Any
5-
import pytest
4+
from typing import Dict, Any, Optional
65

7-
LAST_RUN_FILE = "./.test_last_runs.json"
6+
PROJECT_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))
7+
LAST_RUN_FILE = os.path.join(PROJECT_ROOT, ".test_last_runs.json")
88

99

1010
def load_last_run_data() -> Dict[str, Any]:
@@ -37,7 +37,7 @@ def save_last_run_data(data: Dict[str, Any]) -> None:
3737
json.dump(data, f, indent=2)
3838

3939

40-
def has_test_run_today(test_name: str) -> bool:
40+
def has_test_run_today(test_name: str, base_url: Optional[str] = None) -> bool:
4141
"""
4242
Checks if the given test has already run today.
4343
If not, updates the record to mark it as run today.
@@ -50,10 +50,12 @@ def has_test_run_today(test_name: str) -> bool:
5050
"""
5151
data = load_last_run_data()
5252
today = date.today().isoformat()
53+
env = base_url or "unknown"
5354

54-
if data.get(test_name) == today:
55+
last_run = data.get(test_name, {})
56+
if last_run.get("date") == today and last_run.get("env") == env:
5557
return True
5658
else:
57-
data[test_name] = today
59+
data[test_name] = {"date": today, "env": env}
5860
save_last_run_data(data)
5961
return False

0 commit comments

Comments
 (0)