Improve exception message building #14
GitHub Actions / Test Results
failed
Dec 7, 2024 in 0s
2 fail, 2 skipped, 72 pass in 15s
Annotations
Check warning on line 0 in test.test_uielement
github-actions / Test Results
test_uninitialized_ui_element_fails (test.test_uielement) failed
test-results/tests.xml [took 0s]
Raw output
TypeError: argument of type 'Exception' is not iterable
finder = <paf.page.FinderPage object at 0x7f5ae6711250>
def test_uninitialized_ui_element_fails(finder: FinderPage):
with pytest.raises(Exception) as e:
ui_element = DefaultUiElement(By.id("id"))
ui_element.click()
> assert "initialized without WebDriver nor UiElement" in e.value.args[0]
E TypeError: argument of type 'Exception' is not iterable
test/test_uielement.py:285: TypeError
Check warning on line 0 in test.test_uielement
github-actions / Test Results
test_fail_message (test.test_uielement) failed
test-results/tests.xml [took 0s]
Raw output
AssertionError: Regex pattern did not match.
Regex: 'Expected\\ UiElement\\(By\\.css\\ selector\\(\\#para1\\)\\)\\[0\\]\\.text\\ \\[A\\ paragraph\\ of\\ text\\]\\ mapped\\ ends\\ with\\ \\[Katze\\]\\ to\\ be\\ \\[True\\]'
Input: 'Expected UiElement(By.css selector(#para1))[0].text [A paragraph of text]mappedends with [Katze] to be [True] after 0 retries (0.02 seconds)'
self = <paf.assertion.BinaryAssertion object at 0x7f5ae6726710>
test = <function BinaryAssertion.be.<locals>.<lambda> at 0x7f5ae67ba700>
additional_subject = <function BinaryAssertion.be.<locals>.<lambda> at 0x7f5ae67ba7a0>
def _test_sequence(
self,
test: Predicate[ACTUAL_TYPE],
additional_subject: Supplier = None,
) -> bool:
from paf.listener import Listener
listener = inject.instance(Listener)
try:
def perform_test():
assert test(self.actual), "Expected"
> retry(perform_test, lambda e: listener.assertion_failed(self, self._find_closest_ui_element(), e))
paf/assertion.py:78:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
action = <function AbstractAssertion._test_sequence.<locals>.perform_test at 0x7f5ae67ba840>
on_fail = <function AbstractAssertion._test_sequence.<locals>.<lambda> at 0x7f5ae67ba8e0>
def retry(action: Callable, on_fail: Consumer[Exception] = None):
config = get_config()
sequence = Sequence(retry_count=config.retry_count, wait_after_fail=config.wait_after_fail)
exception: Optional[Exception] = None
def _run():
nonlocal exception
try:
action()
exception = None
return True
except Exception as e:
exception = e
if on_fail:
on_fail(e)
sequence.run(_run)
if exception is not None:
> raise RetryException(exception, sequence)
E paf.common.RetryException: Expected UiElement(By.css selector(#para1))[0].text [A paragraph of text]mappedends with [Katze] to be [True] after 0 retries (0.02 seconds)
paf/control.py:70: RetryException
During handling of the above exception, another exception occurred:
finder = <paf.page.FinderPage object at 0x7f5ae6726890>
def test_fail_message(finder: FinderPage):
finder.open("https://testpages.herokuapp.com/styled/basic-web-page-test.html")
p1 = finder.find("#para1")
with pytest.raises(AssertionError, match=re.escape("Expected UiElement(By.css selector(#para1))[0].text [A paragraph of text] mapped ends with [Katze] to be [True]")):
with change(retry_count=0):
> p1.expect.text.map(str.lower).ends_with("Katze").be(True)
test/test_uielement.py:301:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <paf.assertion.BinaryAssertion object at 0x7f5ae6726710>, expected = True
def be(self, expected: any) -> bool:
> return self._test_sequence(lambda actual: actual == expected, lambda: f"to be {Format.param(expected)}")
paf/assertion.py:117:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <paf.assertion.BinaryAssertion object at 0x7f5ae6726710>
test = <function BinaryAssertion.be.<locals>.<lambda> at 0x7f5ae67ba700>
additional_subject = <function BinaryAssertion.be.<locals>.<lambda> at 0x7f5ae67ba7a0>
def _test_sequence(
self,
test: Predicate[ACTUAL_TYPE],
additional_subject: Supplier = None,
) -> bool:
from paf.listener import Listener
listener = inject.instance(Listener)
try:
def perform_test():
assert test(self.actual), "Expected"
retry(perform_test, lambda e: listener.assertion_failed(self, self._find_closest_ui_element(), e))
listener.assertion_passed(self, self._find_closest_ui_element())
return True
except RetryException as exception:
exception.add_subject(self.name_path)
if additional_subject:
exception.add_subject(additional_subject())
#exception.update_sequence(sequence)
listener.assertion_failed_finally(self, self._find_closest_ui_element(), exception)
if self._raise:
> raise AssertionErrorWrapper(exception)
E paf.assertion.AssertionErrorWrapper: Expected UiElement(By.css selector(#para1))[0].text [A paragraph of text]mappedends with [Katze] to be [True] after 0 retries (0.02 seconds)
paf/assertion.py:90: AssertionErrorWrapper
During handling of the above exception, another exception occurred:
finder = <paf.page.FinderPage object at 0x7f5ae6726890>
def test_fail_message(finder: FinderPage):
finder.open("https://testpages.herokuapp.com/styled/basic-web-page-test.html")
p1 = finder.find("#para1")
> with pytest.raises(AssertionError, match=re.escape("Expected UiElement(By.css selector(#para1))[0].text [A paragraph of text] mapped ends with [Katze] to be [True]")):
E AssertionError: Regex pattern did not match.
E Regex: 'Expected\\ UiElement\\(By\\.css\\ selector\\(\\#para1\\)\\)\\[0\\]\\.text\\ \\[A\\ paragraph\\ of\\ text\\]\\ mapped\\ ends\\ with\\ \\[Katze\\]\\ to\\ be\\ \\[True\\]'
E Input: 'Expected UiElement(By.css selector(#para1))[0].text [A paragraph of text]mappedends with [Katze] to be [True] after 0 retries (0.02 seconds)'
test/test_uielement.py:299: AssertionError
Loading