feat(pytest): strip ansi codes from errors

This commit is contained in:
Rónán Carrigan
2025-09-19 12:16:58 +01:00
parent ed9b4d794b
commit 1b1b1abf92
2 changed files with 5 additions and 3 deletions

View File

@@ -1,6 +1,7 @@
from io import StringIO
import json
from pathlib import Path
import re
from typing import Callable, Dict, List, Optional, Union
import pytest
@@ -10,6 +11,7 @@ from _pytest.fixtures import FixtureLookupErrorRepr
from .base import NeotestAdapter, NeotestError, NeotestResult, NeotestResultStatus
ANSI_ESCAPE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])')
class PytestNeotestAdapter(NeotestAdapter):
def __init__(self, emit_parameterized_ids: bool):
@@ -131,7 +133,7 @@ class NeotestResultCollector:
errors.append({"message": msg_prefix + exc_repr, "line": None})
# Test failed internally
elif isinstance(exc_repr, ExceptionRepr):
error_message = exc_repr.reprcrash.message # type: ignore
error_message = ANSI_ESCAPE.sub('', exc_repr.reprcrash.message) # type: ignore
error_line = None
for traceback_entry in reversed(call.excinfo.traceback):
if str(traceback_entry.path) == abs_path: