Subscribe¶
The Reporter Client supports subscribing to the Reporter Server for live
updates about each section starting and stopping. pyats.reporter.ReportClient
has an async function subscribe(callback)
for this purpose. Users must be
familiar with asyncio in order to leverage this API.
API¶
subscribe(callback)
takes only one argument which is an async function to call
with event data each time it is received.
Example:
import asyncio
from pyats.reporter import ReportClient
async def my_callback(event):
# handle event data
pass
client = ReportClient(path_to_socket)
loop = asyncio.get_event_loop()
loop.run_until_complete(client.subscribe(my_callback))
Event Data¶
Event data is a dict
of information about an event that just occurred. All of
the possible entries are listed in the following table:
Key |
Description |
---|---|
|
A string to specify what kind of event occurred such as ‘start_task’ or ‘stop_section’ |
|
The type of section that triggered this event |
|
A unique number specific to the section triggering this event |
|
The seq_num of the parent section if there is one |
|
The id of the related section |
|
The name of the related section |
|
A timestamp for when the section started |
|
A timestamp for when the section ended |
|
How many seconds the section ran for |
|
The result of the section |
|
The name of the log file |
|
A mapping of log file name, and offset of relevant section of logs |
|
The location of this section in the script |
Only values that exist for that section are included in the event data.
Two notable divergences from typical start_
and stop_
events are
init_testsuite
and init_task
. A pre-task plugin is associated with a
specific Task, but runs before that Task starts. With init_task
the Task is
defined before either the Task or the plugin runs. This allows the plugin to be
associated with that Task despite preceding it. This also applies to pre-job
tasks and the Testsuite.
Section author: Ben Astell <bastell@cisco.com>