@@ -12,7 +12,7 @@ def load_last_run_data() -> Dict[str, Any]:
1212 Loads the last run data from the JSON file.
1313
1414 Returns:
15- Dict[str, Any]: A dictionary mapping test names to their last run date.
15+ Dict[str, Any]: A dictionary mapping environments to test names and their last run date.
1616 """
1717 if os .path .exists (LAST_RUN_FILE ):
1818 try :
@@ -31,31 +31,39 @@ def save_last_run_data(data: Dict[str, Any]) -> None:
3131 Saves the last run data to the JSON file.
3232
3333 Args:
34- data (Dict[str, Any]): The data to save, mapping test names to their last run date.
34+ data (Dict[str, Any]): The data to save, mapping environments to test names and their last run date.
3535 """
3636 with open (LAST_RUN_FILE , "w" ) as f :
3737 json .dump (data , f , indent = 2 )
3838
3939
4040def has_test_run_today (test_name : str , base_url : Optional [str ] = None ) -> bool :
4141 """
42- Checks if the given test has already run today.
43- If not, updates the record to mark it as run today.
42+ Checks if the given test has already run today in the given environment .
43+ If not, updates the record to mark it as run today for that environment .
4444
4545 Args:
4646 test_name (str): The name of the test to check.
47+ base_url (str, optional): The environment base URL.
4748
4849 Returns:
49- bool: True if the test has already run today, False otherwise.
50+ bool: True if the test has already run today in this environment , False otherwise.
5051 """
5152 data = load_last_run_data ()
5253 today = date .today ().isoformat ()
5354 env = base_url or "unknown"
5455
55- last_run = data .get (test_name , {})
56- if last_run .get ("date" ) == today and last_run .get ("env" ) == env :
56+ # Ensure the environment key exists
57+ env_data = data .get (env , {})
58+
59+ # Check if the test has run today in this environment
60+ last_run = env_data .get (test_name , {})
61+ if last_run .get ("date" ) == today :
5762 return True
5863 else :
59- data [test_name ] = {"date" : today , "env" : env }
64+ # Update only the relevant environment/test combination
65+ if env not in data :
66+ data [env ] = {}
67+ data [env ][test_name ] = {"date" : today }
6068 save_last_run_data (data )
6169 return False
0 commit comments