@@ -7,6 +7,16 @@ def random_hex():
77 return secrets .token_hex (2 )
88
99
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+
1020@pytest .fixture (scope = "session" )
1121def yep_code_env ():
1222 env = YepCodeEnv ()
@@ -46,15 +56,16 @@ def test_manage_env_vars(yep_code_env):
4656
4757def test_run_javascript_code (yep_code_run ):
4858 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}}!`
5162 console.log(message)
52- return { message }
53- }
63+ return {{ message } }
64+ }}
5465
55- module.exports = {
66+ module.exports = {{
5667 main,
57- };""" ,
68+ }} ;""" ,
5869 {"removeOnDone" : True },
5970 )
6071 execution .wait_for_done ()
@@ -64,12 +75,13 @@ def test_run_javascript_code(yep_code_run):
6475
6576def test_run_python_code (yep_code_run ):
6677 execution = yep_code_run .run (
67- """import os
78+ f """import os
6879
6980def main():
70- message = f"Hello, {os.getenv('WORLD_ENV_VAR')}!"
81+ { random_py_comment ()}
82+ message = f"Hello, {{os.getenv('WORLD_ENV_VAR')}}!"
7183 print(message)
72- return {"message": message}""" ,
84+ return {{ "message": message} }""" ,
7385 {"removeOnDone" : True },
7486 )
7587 execution .wait_for_done ()
@@ -80,13 +92,14 @@ def main():
8092def test_trigger_on_log (yep_code_run ):
8193 logs = []
8294 execution = yep_code_run .run (
83- """async function main() {
95+ f"""async function main() {{
96+ { random_js_comment ()}
8497 console.log("Log message 1")
8598 console.log("Log message 2")
86- return { success: true }
87- }
99+ return {{ success: true } }
100+ }}
88101
89- module.exports = { main };""" ,
102+ module.exports = {{ main } };""" ,
90103 {
91104 "removeOnDone" : True ,
92105 "onLog" : lambda log_entry : logs .append (log_entry .message ),
@@ -106,11 +119,12 @@ def on_finish(return_value):
106119 finish_value = return_value
107120
108121 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+ }}
112126
113- module.exports = { main };""" ,
127+ module.exports = {{ main } };""" ,
114128 {"removeOnDone" : True , "onFinish" : on_finish },
115129 )
116130
@@ -126,11 +140,12 @@ def on_error(error):
126140 error_message = error ["message" ]
127141
128142 execution = yep_code_run .run (
129- """async function main() {
143+ f"""async function main() {{
144+ { random_js_comment ()}
130145 throw new Error("Test error");
131- }
146+ }}
132147
133- module.exports = { main };""" ,
148+ module.exports = {{ main } };""" ,
134149 {"removeOnDone" : True , "onError" : on_error },
135150 )
136151
@@ -147,10 +162,11 @@ def on_finish(return_value):
147162 finish_value = return_value
148163
149164 execution = yep_code_run .run (
150- """def main():
165+ f"""def main():
166+ { random_py_comment ()}
151167 print("Log message 1")
152168 print("Log message 2")
153- return {"data": "python test"}""" ,
169+ return {{ "data": "python test"} }""" ,
154170 {
155171 "language" : "python" ,
156172 "removeOnDone" : True ,
0 commit comments