Fixtures¶
- saltfactories.plugins.event_listener.event_listener(request)[source]
All started daemons will forward their events into an instance of
EventListener
.This fixture can be used to wait for events:
def test_send(event_listener, salt_master, salt_minion, salt_call_cli): event_tag = random_string("salt/test/event/") data = {"event.fire": "just test it!!!!"} start_time = time.time() ret = salt_call_cli.run("event.send", event_tag, data=data) assert ret.exitcode == 0 assert ret.json assert ret.json is True event_pattern = (salt_master.id, event_tag) matched_events = event_listener.wait_for_events( [event_pattern], after_time=start_time, timeout=30 ) assert matched_events.found_all_events # At this stage, we got all the events we were waiting for
And assert against those events events:
def test_send(event_listener, salt_master, salt_minion, salt_call_cli): # ... check the example above for the initial code ... assert matched_events.found_all_events # At this stage, we got all the events we were waiting for for event in matched_events: assert event.data["id"] == salt_minion.id assert event.data["cmd"] == "_minion_event" assert "event.fire" in event.data["data"]
configure_loader_modules
¶
Note
The configure_loader_modules
fixture is meant to be used on unit-tests, the pytest-salt-factories
plugin
does not define it anywhere. Instead, the user must define it on the test module.
The fixture must return a dictionary, where the keys are the salt modules that need to be patched, and the values
are dictionaries. These dictionaries should have the
salt dunders
as keys. These dunders are dictionaries that the
salt loader injects at runtime, so, they are not available outside of Salt’s runtime.