22
33These hit the real COMcheck Web API and need a valid ``COM_API_KEY``. They
44skip (rather than fail) when no key is set or the key is rejected, so the
5- offline suite stays green; provide a valid key to exercise them.
5+ offline suite stays green; provide a valid key to exercise them. Set
6+ ``REQUIRE_LIVE_API=1`` (as the scheduled integration workflow does) to make
7+ those cases fail instead of skip.
68"""
79
810import os
1921load_dotenv ()
2022
2123
24+ def _skip_or_fail (reason : str ) -> None :
25+ """Skip the live test, or fail it when ``REQUIRE_LIVE_API`` is set."""
26+ if os .getenv ("REQUIRE_LIVE_API" ) == "1" :
27+ pytest .fail (reason )
28+ pytest .skip (reason )
29+
30+
2231@pytest .fixture (scope = "module" )
2332def client ():
2433 """Fixture to create and configure COMcheckClient."""
2534 api_key = os .getenv ("COM_API_KEY" )
2635 if not api_key :
27- pytest . skip ("COM_API_KEY is not set; skipping live client tests." )
36+ _skip_or_fail ("COM_API_KEY is not set; skipping live client tests." )
2837
2938 client = COMcheckClient ()
3039 client .set_api_key (api_key )
@@ -37,7 +46,7 @@ def test_fetch_project_list(client: COMcheckClient):
3746 project_list = client .list_projects ()
3847 except COMCheckHTTPError as exc :
3948 if exc .status_code in (401 , 403 ):
40- pytest . skip (
49+ _skip_or_fail (
4150 f"COM_API_KEY rejected ({ exc .status_code } ); skipping live test."
4251 )
4352 raise
@@ -50,7 +59,7 @@ def test_fetch_single_project(client: COMcheckClient):
5059 project_list = client .list_projects ()
5160 except COMCheckHTTPError as exc :
5261 if exc .status_code in (401 , 403 ):
53- pytest . skip (
62+ _skip_or_fail (
5463 f"COM_API_KEY rejected ({ exc .status_code } ); skipping live test."
5564 )
5665 raise
@@ -77,7 +86,7 @@ def test_calculate_interior_space_allowed_wattage(client: COMcheckClient):
7786 )
7887 except COMCheckHTTPError as exc :
7988 if exc .status_code in (401 , 403 ):
80- pytest . skip (
89+ _skip_or_fail (
8190 f"COM_API_KEY rejected ({ exc .status_code } ); skipping live test."
8291 )
8392 raise
@@ -105,7 +114,7 @@ def test_calculate_interior_spaces_allowed_wattage(client: COMcheckClient):
105114 )
106115 except COMCheckHTTPError as exc :
107116 if exc .status_code in (401 , 403 ):
108- pytest . skip (
117+ _skip_or_fail (
109118 f"COM_API_KEY rejected ({ exc .status_code } ); skipping live test."
110119 )
111120 raise
0 commit comments