@@ -7,6 +7,16 @@ def random_hex():
7
7
return secrets .token_hex (2 )
8
8
9
9
10
+ def random_js_comment ():
11
+ """Generate a random JavaScript comment to avoid parallel execution conflicts"""
12
+ return f"// random comment to avoid parallel executions conflict { random_hex ()} "
13
+
14
+
15
+ def random_py_comment ():
16
+ """Generate a random Python comment to avoid parallel execution conflicts"""
17
+ return f"# random comment to avoid parallel executions conflict { random_hex ()} "
18
+
19
+
10
20
@pytest .fixture (scope = "session" )
11
21
def yep_code_env ():
12
22
env = YepCodeEnv ()
@@ -46,15 +56,16 @@ def test_manage_env_vars(yep_code_env):
46
56
47
57
def test_run_javascript_code (yep_code_run ):
48
58
execution = yep_code_run .run (
49
- """async function main() {
50
- const message = `Hello, ${process.env.WORLD_ENV_VAR}!`
59
+ f"""async function main() {{
60
+ { random_js_comment ()}
61
+ const message = `Hello, ${{process.env.WORLD_ENV_VAR}}!`
51
62
console.log(message)
52
- return { message }
53
- }
63
+ return {{ message } }
64
+ }}
54
65
55
- module.exports = {
66
+ module.exports = {{
56
67
main,
57
- };""" ,
68
+ }} ;""" ,
58
69
{"removeOnDone" : True },
59
70
)
60
71
execution .wait_for_done ()
@@ -64,12 +75,13 @@ def test_run_javascript_code(yep_code_run):
64
75
65
76
def test_run_python_code (yep_code_run ):
66
77
execution = yep_code_run .run (
67
- """import os
78
+ f """import os
68
79
69
80
def main():
70
- message = f"Hello, {os.getenv('WORLD_ENV_VAR')}!"
81
+ { random_py_comment ()}
82
+ message = f"Hello, {{os.getenv('WORLD_ENV_VAR')}}!"
71
83
print(message)
72
- return {"message": message}""" ,
84
+ return {{ "message": message} }""" ,
73
85
{"removeOnDone" : True },
74
86
)
75
87
execution .wait_for_done ()
@@ -80,13 +92,14 @@ def main():
80
92
def test_trigger_on_log (yep_code_run ):
81
93
logs = []
82
94
execution = yep_code_run .run (
83
- """async function main() {
95
+ f"""async function main() {{
96
+ { random_js_comment ()}
84
97
console.log("Log message 1")
85
98
console.log("Log message 2")
86
- return { success: true }
87
- }
99
+ return {{ success: true } }
100
+ }}
88
101
89
- module.exports = { main };""" ,
102
+ module.exports = {{ main } };""" ,
90
103
{
91
104
"removeOnDone" : True ,
92
105
"onLog" : lambda log_entry : logs .append (log_entry .message ),
@@ -106,11 +119,12 @@ def on_finish(return_value):
106
119
finish_value = return_value
107
120
108
121
execution = yep_code_run .run (
109
- """async function main() {
110
- return { data: "test data" }
111
- }
122
+ f"""async function main() {{
123
+ { random_js_comment ()}
124
+ return {{ data: "test data" }}
125
+ }}
112
126
113
- module.exports = { main };""" ,
127
+ module.exports = {{ main } };""" ,
114
128
{"removeOnDone" : True , "onFinish" : on_finish },
115
129
)
116
130
@@ -126,11 +140,12 @@ def on_error(error):
126
140
error_message = error ["message" ]
127
141
128
142
execution = yep_code_run .run (
129
- """async function main() {
143
+ f"""async function main() {{
144
+ { random_js_comment ()}
130
145
throw new Error("Test error");
131
- }
146
+ }}
132
147
133
- module.exports = { main };""" ,
148
+ module.exports = {{ main } };""" ,
134
149
{"removeOnDone" : True , "onError" : on_error },
135
150
)
136
151
@@ -147,10 +162,11 @@ def on_finish(return_value):
147
162
finish_value = return_value
148
163
149
164
execution = yep_code_run .run (
150
- """def main():
165
+ f"""def main():
166
+ { random_py_comment ()}
151
167
print("Log message 1")
152
168
print("Log message 2")
153
- return {"data": "python test"}""" ,
169
+ return {{ "data": "python test"} }""" ,
154
170
{
155
171
"language" : "python" ,
156
172
"removeOnDone" : True ,
0 commit comments