Eventually matcher should catch exceptions on the callable

Bug #1312384 reported by Leo Arias
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Autopilot
Triaged
High
Unassigned

Bug Description

With the current implementation of eventually, if the callable passed as the first argument raises an exception, it will be propagated and the assertion will fail.

I was expecting eventually to catch this exception and keep retrying until it times out. And just at this moment raise the exception.

This is the statement I would like to use:

self.assertThat(
            fake_url_dispatcher.get_last_dispatch_url_call_parameter,
            Eventually(Equals('settings:///system/online-accounts')))

get_last_dispatch_url_call_parameter raises an exception if URL dispatcher hasn't been called. It's eventually called, and then returns the value.

As a workaround, I had to wrap it in a function that catches the exception and returns None. This doesn't seem correct, because then I can't test for cases when the parameter passed to the fake service is None.

Tags: elopio qa-new
Revision history for this message
Thomi Richards (thomir-deactivatedaccount) wrote :

Hi,

I agree with your problem description, but not with the proposed solution.

The issue here is that Eventually takes callables, and calls them. This is inconsistent with the Matcher API, and introduces other problems as well (for example, you cannot use Eventually and 'raises' matchers together).

I'd rather solve this by deprecating the ability to pass a naked callable to Eventually, and instead encourage people to use the AfterProcessing matcher, or soemthing similar. You could conceptially do:

self.assertThat(
        fake_url_dispatcher.get_last_dispatch_url_call_parameter,
        Eventually(
            AfterProcessing(StripException, Equals('settings:///system/online-accounts'))
       )
)

Or something similar.

Changed in autopilot:
status: New → Triaged
importance: Undecided → High
tags: added: ap-perf
tags: removed: ap-perf
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.