testplan.common.report package

Submodules

testplan.common.report.base module

Base classes for building a report tree.

The idea behind this module is that we may have parallel runners for a testplan, each of which would generate a partial report.

Later on these reports would be merged together to build the final report as the testplan result.

class testplan.common.report.base.ExceptionLogger(*exception_classes, **kwargs)[source]

Bases: object

A context manager used for suppressing & logging an exception.

exception testplan.common.report.base.MergeError[source]

Bases: Exception

Raised when a merge operation fails.

class testplan.common.report.base.Report(name: str, description: Optional[str] = None, definition_name: Optional[str] = None, uid: Optional[str] = None, entries: Optional[list] = None, parent_uids: Optional[List[str]] = None)[source]

Bases: object

Base report class, support exception suppression & logging via report.logged_exceptions. Stores arbitrary objects in entries attribute.

append(item)[source]

Append item to self.entries, no restrictions.

exception_logger

alias of ExceptionLogger

extend(items)[source]

Extend self.entries with items, no restrictions.

filter(*functions, **kwargs)[source]

Filtering report’s entries in place using the given functions. If any of the functions return True for a given entry, it will be kept.

flattened_entries(depth)[source]

Utility function that is used by TestGroupReport.flatten.

This method should be overridden if entries have a custom hierarchy instead of a simple list.

hash

Return a hash of all entries in this report.

is_empty() → bool[source]

Check report is empty or not.

logged_exceptions(*exception_classes, **kwargs)[source]

Wrapper around ExceptionRecorder, passing report arg implicitly.

Basic usage:

with report.logged_exceptions(TypeError, ValueError):
    raise some errors here ...
merge(report, strict=True)[source]

Child classes can override this, just make sure merge operation is idempotent, so that merging the same report onto self multiple times does not create extra data.

Parameters:
  • report (Report) – Report that contains logs to merge.
  • strict (bool) – Flag for enabling / disabling strict merge ops.
reset_uid(uid=None)[source]

Reset uid of the report, it can be useful when need to generate a global unique id instead of the current one.

class testplan.common.report.base.ReportGroup(name: str, events: Dict[KT, VT] = None, host: Optional[str] = None, **kwargs)[source]

Bases: testplan.common.report.base.Report

A report class that contains other Reports or ReportGroups in entries. Allows O(1) child report lookup via get_by_uid method.

add_event(event_executor: testplan.monitor.event.EventRecorder, event_id: Optional[str] = None) → str[source]
append(item)[source]

Add item to self.entries, checking type & index.

build_index(recursive=False)[source]

Build (refresh) indexes for this report and optionally for each child report.

This should be called explicitly if self.entries is changed.

Parameters:recursive (bool) – Flag for triggering index build on children.
entry_uids

Return the UIDs of all entries in this report group.

events
extend(items)[source]

Add items to self.entries, checking type & index.

filter(*functions, **kwargs)[source]

Recursively filter report entries and sub-entries.

flatten(depths=False)[source]

Depth-first traverse the report tree starting on the leftmost node (smallest index), return a list of (depth, obj) tuples or a list of reports depending on depths flag.

Parameters:depths – Flag for enabling/disabling depth data in result.
Returns:List of reports or list of (depth, report) tuples.
flattened_logs

Return a flattened list of the logs from each Report.

get_by_uid(uid)[source]

Get child report via uid lookup.

Parameters:uid (hashable) – uid for the child report.
get_by_uids(uids)[source]

Get child report via a series of uid lookup.

Parameters:uids (list of hashable) – A uid for the child report.
has_uid(uid)[source]

Has a child report of uid

merge(report, strict=True)[source]

Merge child reports first, propagating strict flag.

merge_children(report, strict=True)[source]

Merge each children separately, raising MergeError if uid does not match.

reset_uid(uid=None)[source]

Reset uid of test report and all of its children, it can be useful when need to generate global unique id for each report entry before saving, by default strings in standard UUID format will be applied.

set_by_uid(uid, item)[source]

Set child report via uid lookup.

If an entry with a matching UID is already present, that entry is updated. Otherwise a new entry will be added.

Parameters:
  • uid (hashable) – uid for the child report.
  • item (Report) – entry to update or insert into the report.
set_parent_uids(item)[source]

Set the parent UIDs recursively of an item and its child entries after it has been added into this report group.

exception testplan.common.report.base.SkipTestcaseException[source]

Bases: Exception

Raised from an explicit call to result.skip.

testplan.common.report.log module

We’d like to use python’s logging interface when we log messages through Report objects. The most lightweight way to do it is to use a logging.LoggingAdapter which is a thin wrapper around a logging.Logger.

We can then use a global mapping and a custom handler to append log messages to the report object’s logs list.

class testplan.common.report.log.ReportLogHandler(level=0)[source]

Bases: logging.Handler

Log handler that uses the global report map for appending log messages to report objects.

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

testplan.common.report.log.create_logging_adapter(report)[source]

Create a new adapter and bind the report to global REPORT_MAP so handler can access it.

testplan.common.report.schemas module

Base schemas for report serialization.

class testplan.common.report.schemas.ReportLogSchema(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]

Bases: marshmallow.schema.Schema

Schema for log record data created by report stdout.

opts = <marshmallow.schema.SchemaOpts object>
class testplan.common.report.schemas.ReportSchema(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]

Bases: testplan.common.serialization.schemas.TreeNodeSchema

Schema for base.Report.

class Meta[source]

Bases: object

unknown = 'exclude'
make_report(data, **kwargs)[source]

Create report object, attach log list.

opts = <marshmallow.schema.SchemaOpts object>
source_class

alias of testplan.common.report.base.Report

class testplan.common.report.schemas.ReportGroupSchema(*, only: types.StrSequenceOrSet | None = None, exclude: types.StrSequenceOrSet = (), many: bool = False, context: dict | None = None, load_only: types.StrSequenceOrSet = (), dump_only: types.StrSequenceOrSet = (), partial: bool | types.StrSequenceOrSet = False, unknown: str | None = None)[source]

Bases: testplan.common.report.schemas.ReportSchema

Schema for base.ReportGroup.

opts = <marshmallow.schema.SchemaOpts object>
source_class

alias of testplan.common.report.base.ReportGroup

Module contents