Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ANSI escape color codes from log output in Python tests #330

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/validation/Engine/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import time
from queue import Queue
from typing import Any, List
import re

import pytest
from pytest_check import check
Expand Down Expand Up @@ -85,10 +86,13 @@ def readproc(process: subprocess.Popen):
case_id = case_id[: case_id.rfind("(") - 1]
logfile = os.path.join(LOG_FOLDER, "latest", f"{case_id}.pid{process.pid}.log")

ansi_esc = re.compile(r'\x1b\[[0-9;]*m')

output = []
with open(logfile, "w") as file:
if process.stdout is not None:
for line in iter(process.stdout.readline, ""):
line = ansi_esc.sub('', line) # Remove ANSI escape color codes
output.append(line)
file.write(line)
return "".join(output)
Expand Down