44import pytest
55from dotenv import load_dotenv
66
7- from judge0 import clients
7+ from judge0 import clients , RegularPeriodRetry
88
99load_dotenv ()
1010
@@ -34,55 +34,71 @@ def custom_extra_ce_client():
3434@pytest .fixture (scope = "session" )
3535def atd_ce_client ():
3636 api_key = os .getenv ("JUDGE0_ATD_API_KEY" )
37- client = clients .ATDJudge0CE (api_key )
38- return client
37+
38+ if api_key is None :
39+ return None
40+ else :
41+ return clients .ATDJudge0CE (api_key )
3942
4043
4144@pytest .fixture (scope = "session" )
4245def atd_extra_ce_client ():
4346 api_key = os .getenv ("JUDGE0_ATD_API_KEY" )
44- client = clients .ATDJudge0ExtraCE (api_key )
45- return client
47+
48+ if api_key is None :
49+ return None
50+ else :
51+ return clients .ATDJudge0ExtraCE (api_key )
4652
4753
4854@pytest .fixture (scope = "session" )
4955def rapid_ce_client ():
5056 api_key = os .getenv ("JUDGE0_RAPID_API_KEY" )
51- client = clients .RapidJudge0CE (api_key )
52- return client
57+
58+ if api_key is None :
59+ return None
60+ else :
61+ return clients .RapidJudge0CE (api_key )
5362
5463
5564@pytest .fixture (scope = "session" )
5665def rapid_extra_ce_client ():
5766 api_key = os .getenv ("JUDGE0_RAPID_API_KEY" )
58- client = clients .RapidJudge0ExtraCE (api_key )
59- return client
67+
68+ if api_key is None :
69+ return None
70+ else :
71+ return clients .RapidJudge0ExtraCE (api_key )
6072
6173
6274@pytest .fixture (scope = "session" )
6375def sulu_ce_client ():
6476 api_key = os .getenv ("JUDGE0_SULU_API_KEY" )
65- if api_key is None :
66- pytest .fail (
67- "Sulu API key is not available for testing. Make sure to have "
68- "JUDGE0_SULU_API_KEY in your environment variables."
69- )
7077
71- client = clients .SuluJudge0CE (api_key )
72- return client
78+ if api_key is None :
79+ return None
80+ else :
81+ return clients .SuluJudge0CE (api_key )
7382
7483
7584@pytest .fixture (scope = "session" )
7685def sulu_extra_ce_client ():
7786 api_key = os .getenv ("JUDGE0_SULU_API_KEY" )
87+
7888 if api_key is None :
79- pytest .fail (
80- "Sulu API key is not available for testing. Make sure to have "
81- "JUDGE0_SULU_API_KEY in your environment variables."
82- )
89+ return None
90+ else :
91+ return clients .SuluJudge0ExtraCE (api_key )
8392
84- client = clients .SuluJudge0ExtraCE (api_key )
85- return client
93+
94+ @pytest .fixture (scope = "session" )
95+ def preview_ce_client () -> clients .SuluJudge0CE :
96+ return clients .SuluJudge0CE (retry_strategy = RegularPeriodRetry (0.5 ))
97+
98+
99+ @pytest .fixture (scope = "session" )
100+ def preview_extra_ce_client () -> clients .SuluJudge0ExtraCE :
101+ return clients .SuluJudge0ExtraCE (retry_strategy = RegularPeriodRetry (0.5 ))
86102
87103
88104@pytest .fixture (scope = "session" )
@@ -91,6 +107,7 @@ def ce_client(
91107 sulu_ce_client ,
92108 rapid_ce_client ,
93109 atd_ce_client ,
110+ preview_ce_client ,
94111):
95112 if custom_ce_client is not None :
96113 return custom_ce_client
@@ -100,8 +117,10 @@ def ce_client(
100117 return rapid_ce_client
101118 if atd_ce_client is not None :
102119 return atd_ce_client
120+ if preview_ce_client is not None :
121+ return preview_ce_client
103122
104- pytest .fail ("No CE client available for testing." )
123+ pytest .fail ("No CE client available for testing. This error should not happen! " )
105124
106125
107126@pytest .fixture (scope = "session" )
@@ -110,6 +129,7 @@ def extra_ce_client(
110129 sulu_extra_ce_client ,
111130 rapid_extra_ce_client ,
112131 atd_extra_ce_client ,
132+ preview_extra_ce_client ,
113133):
114134 if custom_extra_ce_client is not None :
115135 return custom_extra_ce_client
@@ -119,5 +139,9 @@ def extra_ce_client(
119139 return rapid_extra_ce_client
120140 if atd_extra_ce_client is not None :
121141 return atd_extra_ce_client
142+ if preview_extra_ce_client is not None :
143+ return preview_extra_ce_client
122144
123- pytest .fail ("No Extra CE client available for testing." )
145+ pytest .fail (
146+ "No Extra CE client available for testing. This error should not happen!"
147+ )
0 commit comments