Event testing fixture.

The idea of this fixture is to pass some “expected” events to and check whether all expected events are received at the test end.

register_event fixture accepts attributes for one expected event

simple example:

register_event(target_type='VmOrTemplate',, event_type='vm_create')

more complex example:

def add_cmp(_, y):
    data = yaml.safe_load(y)
    return data['resourceId'].endswith(nsg_name) and data['status']['value'] == 'Accepted' and             data['subStatus']['value'] == 'Created'

fd_add_attr = {'full_data': 'will be ignored',
               'cmp_func': add_cmp}

# add network security group event
register_event(fd_add_attr, source='AZURE',

def rm_cmp(_, y):
    data = yaml.safe_load(y)
    return data['resourceId'].endswith(nsg_name) and data['status']['value'] == 'Succeeded'             and len(data['subStatus']['value']) == 0

fd_rm_attr = {'full_data': 'will be ignored',
              'cmp_func': rm_cmp}

# remove network security group event
register_event(fd_rm_attr, source=provider.type.upper(),

Expected events are defined by set of event attributes which should match to the same event attributes in event_streams db table except one fake attribute - target_name which is resolved into certain object’s id.

Default match algorithm is ==. Event also accepts match function in order to change default match type.[source] of event attributes)[source]

Event registration fixture.

This fixture is used to notify the testing system that some event should have occurred during execution of the test case using it. It does not register anything by itself.

  • attribute 1 (event) –

  • ..

  • attribute N (event) –

Returns: None


def test_something(foo, bar, register_event, appliance):
    register_event(target_type = 'VmOrTemplate', target_name =,
        event_type = 'vm_create'), func_args=[], func_kwargs={}, *, logger=<TraceLogger cfme (INFO)>, **kwargs)

Waits for a certain amount of time for an action to complete Designed to wait for a certain length of time, either linearly in 1 second steps, or exponentially, up to a maximum. Returns the output from the function once it completes successfully, along with the time taken to complete the command.

It tries to use time.monotonic(), if it is not present, falls back to time.time(), but it then is not resistant against system time changes.

Note: If using the expo keyword, the returned elapsed time will be inaccurate

as wait_for does not know the exact time that the function returned correctly, only that it returned correctly at last check.

  • func – A function to be run

  • func_args – A list of function arguments to be passed to func

  • func_kwargs – A dict of function keyword arguments to be passed to func

  • num_sec – An int describing the number of seconds to wait before timing out.

  • timeout – Either an int describing the number of seconds to wait before timing out. Or a timedelta object. Or a string formatted like 1h 10m 5s. This then sets the num_sec variable.

  • expo – A boolean flag toggling exponential delay growth.

  • message – A string containing a description of func’s operation. If None, defaults to the function’s name.

  • fail_condition – An object describing the failure condition that should be tested against the output of func. If func() == fail_condition, wait_for continues to wait. Can be a callable which takes the result and returns boolean whether to fail. You can also specify it as a set, that way it checks whether it is present in the iterable.

  • handle_exception – A boolean controlling the handling of excepetions during func() invocation. If set to True, in cases where func() results in an exception, clobber the exception and treat it as a fail_condition.

  • delay – An integer describing the number of seconds to delay before trying func() again.

  • fail_func – A function to be run after every unsuccessful attempt to run func()

  • quiet – Do not write time report to the log (default False)

  • very_quiet – Do not log unless there was an error (default False). Implies quiet.

  • silent_failure – Even if the entire attempt times out, don’t throw a exception.

  • log_on_loop – Fire off a message indicating we’re still waiting at each iteration of the wait loop


A tuple containing the output from func() and a float detailing the total wait time.


TimedOutError – If num_sec is exceeded after an unsuccessful func() invocation.