Skip to content

Provide message of expected exception when timeout happens #12

Open

Description

@abotalov

Currently if both timeout_seconds and expected_exception are used, only information that timeout expired is printed.
It would be good to add exception message of expected exception to TimeoutExpired message.

Activity

  1. vmalloc commented on Sep 27, 2018

    @vmalloc
    Owner

    Can you please provide an example (not necessarily working) code snippet and what you expect to happen with it that currently does not happen? I'm not sure I'm following correctly...

  2. abotalov commented on Sep 27, 2018

    @abotalov
    Author

    Well, I'd like to perform assert until it succeeds or timeout happens.

    def assertion()
      assert window.url() == 'some_string'
    wait(assertion, timeout_seconds=10, expected_exceptions=AssertionError)

    Similar feature exists in pytest-qt (https://pytest-qt.readthedocs.io/en/latest/wait_until.html). There, if timeout happens, an expected exception is raised instead of TimeoutError (https://github.com/pytest-dev/pytest-qt/blob/master/pytestqt/qtbot.py#L520). The benefit is that a user sees a message that helps to understand why timeout has happened.

    waiting library may however still raise TimeoutExpired but a message can be improved to include a message of happened expected exception.

    Currently I see only something like:

    TimeoutExpired: Timeout of 10 seconds expired waiting for <function assertion at 0x1031bdca2>
    
  3. vmalloc commented on Sep 27, 2018

    @vmalloc
    Owner

    expected_exceptions in this case means "exceptions that are allowed to happen while polling", so they are ignored... I don't see the logic behind raising them on timeout....

  4. abotalov commented on Sep 27, 2018

    @abotalov
    Author

    The use case is described above. Could you propose a better way to do it?
    Yes, these exceptions are allowed to happen until timeout. But once timeout happened, the message is useful for debugging.

  5. vmalloc commented on Sep 27, 2018

    @vmalloc
    Owner

    I see...

    What if you had some adapter to achieve this, like:

    waiting.wait(waiting.succeeds(func, expected_exceptions=(...)))
    

    Then in this use case I can make the "default" message formatting consider this object type and print the last exception encountered on it

  6. abotalov commented on Sep 27, 2018

    @abotalov
    Author

    Ah, I just got that a solution I proposed before wouldn't fully work. As successful assertion returns None rather than True. But it could be worked around by returning True from a func.
    Will the mechanism that you wrote about work by raising a specific exception that is catched in wait?

  7. vmalloc commented on Sep 27, 2018

    @vmalloc
    Owner

    I think it will be a specific subclass of a new class which waiting recognized, and which can be queried for the exact reason for not succeeding

  8. abotalov commented on Sep 27, 2018

    @abotalov
    Author

    The following appears to work fine for me:

    def assertion()
      assert window.url() == 'some_string'
      return True
    wait(assertion, timeout_seconds=10, expected_exceptions=AssertionError)

    together with a code change like abotalov@0d43a52 appears to work.
    The code change only outlines idea - it would be better to pass a message as a third parameter and to build a better message in TimeoutExpired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions