Skip to content

Commit

Permalink
Enhance error message normalization in ExpectedFailTest for improved …
Browse files Browse the repository at this point in the history
…feedback clarity
  • Loading branch information
polischuks committed Feb 15, 2025
1 parent d84440b commit 19303af
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions hstest/testing/unittest/expected_fail_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from __future__ import annotations

from inspect import cleandoc
import re
from typing import Any

from hstest import StageTest
from hstest.stage.stage_test import StageTest


class ExpectedFailTest(StageTest):
Expand All @@ -15,6 +17,13 @@ class ExpectedFailTest(StageTest):
def __init__(self, args) -> None:
super().__init__(args)

def normalize_error_message(self, message: str) -> str:
# Remove error pointer markers added in Python 3.11+
message = re.sub(r'\s+[~^]+\s*', ' ', message)
# Normalize whitespace and line breaks
message = ' '.join(message.split())
return message

def test_run_unittest(self) -> None:
if not self.contain and not self.not_contain:
self.fail("'contain' or 'not_contain' should not be empty")
Expand All @@ -35,8 +44,14 @@ def test_run_unittest(self) -> None:
should_contain = self._base_contain + self.contain
should_not_contain = self._base_not_contain + self.not_contain

normalized_feedback = self.normalize_error_message(feedback)

for item in should_contain:
self.assertIn(cleandoc(item), feedback)
normalized_item = self.normalize_error_message(cleandoc(item))
self.assertIn(normalized_item, normalized_feedback,
f"Expected to find:\n{normalized_item}\nin:\n{normalized_feedback}")

for item in should_not_contain:
self.assertNotIn(cleandoc(item), feedback)
normalized_item = self.normalize_error_message(cleandoc(item))
self.assertNotIn(normalized_item, normalized_feedback,
f"Expected NOT to find:\n{normalized_item}\nin:\n{normalized_feedback}")

0 comments on commit 19303af

Please sign in to comment.