4
4
import pytest
5
5
from dotenv import load_dotenv
6
6
7
- from judge0 import clients
7
+ from judge0 import clients , RegularPeriodRetry
8
8
9
9
load_dotenv ()
10
10
@@ -34,55 +34,71 @@ def custom_extra_ce_client():
34
34
@pytest .fixture (scope = "session" )
35
35
def atd_ce_client ():
36
36
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 )
39
42
40
43
41
44
@pytest .fixture (scope = "session" )
42
45
def atd_extra_ce_client ():
43
46
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 )
46
52
47
53
48
54
@pytest .fixture (scope = "session" )
49
55
def rapid_ce_client ():
50
56
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 )
53
62
54
63
55
64
@pytest .fixture (scope = "session" )
56
65
def rapid_extra_ce_client ():
57
66
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 )
60
72
61
73
62
74
@pytest .fixture (scope = "session" )
63
75
def sulu_ce_client ():
64
76
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
- )
70
77
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 )
73
82
74
83
75
84
@pytest .fixture (scope = "session" )
76
85
def sulu_extra_ce_client ():
77
86
api_key = os .getenv ("JUDGE0_SULU_API_KEY" )
87
+
78
88
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 )
83
92
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 ))
86
102
87
103
88
104
@pytest .fixture (scope = "session" )
@@ -91,6 +107,7 @@ def ce_client(
91
107
sulu_ce_client ,
92
108
rapid_ce_client ,
93
109
atd_ce_client ,
110
+ preview_ce_client ,
94
111
):
95
112
if custom_ce_client is not None :
96
113
return custom_ce_client
@@ -100,8 +117,10 @@ def ce_client(
100
117
return rapid_ce_client
101
118
if atd_ce_client is not None :
102
119
return atd_ce_client
120
+ if preview_ce_client is not None :
121
+ return preview_ce_client
103
122
104
- pytest .fail ("No CE client available for testing." )
123
+ pytest .fail ("No CE client available for testing. This error should not happen! " )
105
124
106
125
107
126
@pytest .fixture (scope = "session" )
@@ -110,6 +129,7 @@ def extra_ce_client(
110
129
sulu_extra_ce_client ,
111
130
rapid_extra_ce_client ,
112
131
atd_extra_ce_client ,
132
+ preview_extra_ce_client ,
113
133
):
114
134
if custom_extra_ce_client is not None :
115
135
return custom_extra_ce_client
@@ -119,5 +139,9 @@ def extra_ce_client(
119
139
return rapid_extra_ce_client
120
140
if atd_extra_ce_client is not None :
121
141
return atd_extra_ce_client
142
+ if preview_extra_ce_client is not None :
143
+ return preview_extra_ce_client
122
144
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