Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bandophahita committed Sep 22, 2023
1 parent d506f35 commit 7a7e321
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
17 changes: 14 additions & 3 deletions screenpy/actions/eventually.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"""

import time
from typing import Dict, Optional
from traceback import format_tb
from typing import Optional

from screenpy.actor import Actor
from screenpy.configuration import settings
Expand Down Expand Up @@ -138,7 +139,8 @@ def perform_as(self, the_actor: Actor) -> None:
return
except Exception as exc: # pylint: disable=broad-except
self.caught_error = exc
self.unique_errors[exc] = None
if not any(same_exception(exc, c) for c in self.unique_errors):
self.unique_errors.append(exc)

count += 1
time.sleep(self.poll)
Expand All @@ -158,6 +160,15 @@ def __init__(self, performable: Performable):
self.performable = performable
self.performable_to_log = get_additive_description(self.performable)
self.caught_error = None
self.unique_errors: Dict[Exception, None] = {}
self.unique_errors: list[BaseException] = []
self.timeout = settings.TIMEOUT
self.poll = settings.POLLING


def same_exception(a: BaseException, b: BaseException) -> bool:
"""compare exceptions to see if they match"""
return (
isinstance(a, type(b))
and (str(a) == str(b))
and (format_tb(a.__traceback__) == format_tb(b.__traceback__))
)
18 changes: 18 additions & 0 deletions tests/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,24 @@ def test_mention_all_errors_in_order(self, mocked_time, Tester):
" AssertionError: Failure #5"
)

@mock.patch("screenpy.actions.eventually.time", autospec=True)
def test_mention_multiple_errors_once(self, mocked_time, Tester):
mocked_time.time = mock.create_autospec(time.time, side_effect=[1, 1, 1, 100])
mock_question = FakeQuestion()
mock_question.answered_by.return_value = True
mock_question.describe.return_value = "returns bool"

with pytest.raises(DeliveryError) as actual_exception:
Eventually(See(mock_question, IsEqualTo(False))).perform_as(Tester)

assert str(actual_exception.value) == (
"Tester tried to Eventually see if returns bool is equal to False 3 times "
"over 20.0 seconds, but got:\n"
" AssertionError: \n"
"Expected: <False>\n"
" but: was <True>\n"
)

def test_describe(self) -> None:
mock_action = FakeAction()
mock_action.describe.return_value = "An African or a European swallow?"
Expand Down

0 comments on commit 7a7e321

Please sign in to comment.