fix: conda error information (#941)

* test with conda error

* reformat
This commit is contained in:
Tim
2025-06-06 11:45:48 +08:00
committed by GitHub
parent 1a61d51fa8
commit 5bb5722921
2 changed files with 16 additions and 3 deletions
+4 -3
View File
@@ -445,9 +445,10 @@ class LocalEnv(Env[ASpecificLocalConf]):
Console().print(output.strip(), markup=False)
combined_output += output
elif fd == stderr_fd:
error = process.stderr.readline()
if error:
Console().print(error.strip(), markup=False)
chunk = os.read(stderr_fd, 4096)
if chunk:
error = chunk.decode(errors="replace")
Console().print(error, end="", markup=False)
combined_output += error
# Capture any final output
+12
View File
@@ -1,5 +1,6 @@
import os
import sys
import time
import unittest
from pathlib import Path
@@ -69,6 +70,17 @@ class EnvUtils(unittest.TestCase):
res, code = le.run_ret_code(local_path=str(code_path))
print(res, code)
def test_conda_error(self):
conda_conf = CondaConf(conda_env_name="MLE")
le = LocalEnv(conf=conda_conf)
le.prepare()
file_name = f"{time.time()}.py"
with open(self.test_workspace / file_name, "w") as f:
f.write('import json \njson.loads(b\'{"name": "\xa1"}\')')
res, code = le.run_ret_code(local_path=str(self.test_workspace), entry=f"python {file_name}")
assert code == 1
assert "bytes can only contain ASCII literal characters" in res
def test_docker(self):
"""We will mount `env_tpl` into the docker image.
And run the docker image with `qrun conf.yaml`