feat(pytest): strip ansi codes from errors
This commit is contained in:
@@ -53,7 +53,7 @@ end
|
||||
---@param positions neotest.Tree
|
||||
---@param root string
|
||||
local function discover_params(python, script, path, positions, root)
|
||||
local cmd = vim.tbl_flatten({ python, script, "--pytest-collect", path })
|
||||
local cmd = vim.iter({ python, script, "--pytest-collect", path }):flatten():totable()
|
||||
logger.debug("Running test instance discovery:", cmd)
|
||||
|
||||
local test_params = {}
|
||||
@@ -66,7 +66,7 @@ local function discover_params(python, script, path, positions, root)
|
||||
return {}
|
||||
end
|
||||
|
||||
for line in vim.gsplit(data.stdout, "\n", true) do
|
||||
for line in vim.gsplit(data.stdout, "\n", { plain = true }) do
|
||||
local param_index = string.find(line, "[", nil, true)
|
||||
if param_index then
|
||||
local test_id = root .. lib.files.path.sep .. string.sub(line, 1, param_index - 1)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user