taf.plugins.loggers¶
loggers.py
logging functionality for TAF
-
class
taf.plugins.loggers.ClassLogger(log_level='INFO', log_file=None, log_stream=True, for_exception=False, introspection=True)[source]¶ Bases:
objectClass logger descriptor.
-
__get__(instance, owner)[source]¶ This method is called from class.
Parameters: owner (owner) – class instance. Returns: logger adaptor. Return type: logging.LoggerAdapter Note
In case using logger for module level use get() method. __get__() won’t be called from module level.
-
__init__(log_level='INFO', log_file=None, log_stream=True, for_exception=False, introspection=True)[source]¶ Initialize instance of ClassLogger.
Parameters:
-
_get_logger(modulename, classname='', caller_func='')[source]¶ Configure and return loggerAdapter instance.
Parameters: Returns: logger adaptor.
Return type:
-
-
class
taf.plugins.loggers.LoggerWrapper(logger, level)[source]¶ Bases:
threading.ThreadRead text message from a pipe and redirect them to a logger.
Note
The object itself is able to supply a file descriptor to be used for writing. fdWrite ==> fdRead ==> pipeReader.
-
__init__(logger, level)[source]¶ Setup the object with a logger and a loglevel and start the thread.
-
-
class
taf.plugins.loggers.NoErrArgumentParser(*args, **kwargs)[source]¶ Bases:
argparse.ArgumentParserArgumentParser class that handle only predefined for an instance options.
Note
The original ArgumentParser class raises an error if handle unknown option. But py.test have it’s own options and it’s own custom parser and if ArgumentParser find them it raises an error. Using this class allows not to define all possible options in each module that uses ArgumentParser.
taf.plugins.pytest_caselogger¶
taf.plugins.pytest_heat_checker¶
pytest_heat_checker.py
Plugin is checking temperature
-
class
taf.plugins.pytest_heat_checker.HeatChecker(env, item)[source]¶ Bases:
objectBase class for HeatChecker functionality.
-
__init__(env, item)[source]¶ Initialize HeatChecker instance.
Parameters: - env (testlib.common3.Environment) – Environment instance.
- item (pytest.Item) – Test case instance.
-
-
class
taf.plugins.pytest_heat_checker.HeatCheckerPlugin[source]¶ Bases:
objectLog device’s temperature.
-
heatcheck(request, env)[source]¶ Call heat checker on test case setup/teardown.
Parameters: - request (pytest.request) – Pytest request instance.
- env (testlib.common3.Environment) – ‘env’ pytest fixture from pytest_onsenv.py.
-
taf.plugins.pytest_helpers¶
pytest_helpers.py
pytest specific helpers functions
-
taf.plugins.pytest_helpers.get_brief(item, tc_name)[source]¶ Parse doc-string and return brief.
Parameters: - item (pytest.Item) – pytest test case item
- tc_name (str) – test case name
Returns: test case docstring’s brief
Return type:
-
taf.plugins.pytest_helpers.get_failure_reason(data)[source]¶ Return test case failure reason from report string.
Parameters: data (str) – test case report Returns: failure reason or None Return type: str
-
taf.plugins.pytest_helpers.get_html_xml_path(path, build_name)[source]¶ Parse and replace $BUILD_NAME variable in the path.
Parameters: Returns: modified path to html report
Return type:
-
taf.plugins.pytest_helpers.get_skipped_reason(data)[source]¶ Return test case skip reason from report string.
Parameters: data (str) – test case report Returns: skip reason or None Return type: str
-
taf.plugins.pytest_helpers.get_steps(item, tc_name)[source]¶ Parse and return test steps.
Parameters: - item (pytest.Item) – pytest test case item
- tc_name (str) – test case name
Returns: test case’s steps
Return type:
-
taf.plugins.pytest_helpers.get_suite_name(nodeid)[source]¶ Return suitename from nodeid string.
Parameters: nodeid (str) – pytest.Item nodeid string Returns: test suite name Return type: str
taf.plugins.pytest_loganalyzer¶
taf.plugins.pytest_multiple_run¶
pytest_multiple_run.py
Re-run test case n times
taf.plugins.pytest_multipletg¶
pytest_multipletg.py
Work with several TGs like with one instance
Note
If setup JSON file contains several TG devices they will be handled as one instance.
Use @pytest.mark.multiple_tgs class level marker in order to disable this functionality for particular test suites.
-
class
taf.plugins.pytest_multipletg.MultipleTGClass(env)[source]¶ Bases:
object-
class_logger= <logging.LoggerAdapter object>¶
-
taf.plugins.pytest_onsenv¶
taf.plugins.pytest_pidchecker¶
pytest_pidchecker.py
Plugin is checking processes for being restarted
-
class
taf.plugins.pytest_pidchecker.PidChecker(env, flag, item)[source]¶ Bases:
objectBase class for TAF pidchecker functionality.
-
__init__(env, flag, item)[source]¶ Create PidChecker instance.
Parameters: - env (testlib.common3.Environment) – Environment instance from ‘env’ fixture.
- flag (bool) – Flag to know if plugin should skip process validation.
- item (pytest.Item) – Test case instance.
-
_check_processes_setup(switch, tc_name)[source]¶ Check processes on setup.
Parameters: - switch (testlib.switch_general.SwitchGeneral) – switch instance from test environment.
- tc_name (str) – test case’s name.
-
-
class
taf.plugins.pytest_pidchecker.PidCheckerPlugin[source]¶ Bases:
objectPidCheckerPlugin implementation.
-
pidcheck(request, env)[source]¶ Call ONS processes verification on test case setup/teardown.
Parameters: - request (pytest.request) – pytest request instance.
- env (testlib.common3.Environment) – ‘env’ pytest fixture from pytest_onsenv.py.
-
taf.plugins.pytest_random_collection¶
pytest_random_collection.py
Choose one test case from test suite randomly if random marker is set
-
class
taf.plugins.pytest_random_collection.RandomChoice(seed)[source]¶ Bases:
objectChoose one test case from test suite randomly if random marker is set.
taf.plugins.pytest_reportingserver¶
pytest_reportingserver.py
XML-RPC reporting server plugin
-
class
taf.plugins.pytest_reportingserver.ReportingServer(opts)[source]¶ Bases:
objectLogging xmlrpc server class.
-
REPORTINGSRV_PATH= 'reporting_server.py'¶
-
REPORTINGSRV_TIMEOUT= 30¶
-
UNDEFINED_BUILD= 'Undefined'¶
-
_get_build_info(item=None)[source]¶ Get info about build.
Parameters: item (pytest.Item) – test case item Returns: str, “build”: str}: build info Return type: dict{“platform”
-
_send_post_queue(item=None, buildname=None, sanity=False)[source]¶ Send info about test execution to the Reporting Server.
Parameters:
-
_send_post_request(item)[source]¶ Send post request to reporting server or add it to queue.
Parameters: item (pytest.Item) – test case item
-
_sessionstart(item)[source]¶ Tell to XMLRPC Server that we are going to interact with it.
Parameters: item (pytest.Item) – test case item
-
buildname(env_prop=None)[source]¶ Return buildname for current session.
Parameters: env_prop (dict) – environment information e.g. build, name, etc. Returns: buildname Return type: str
-
check_server(timeout=1)[source]¶ Check if xmlrpc server is alive.
Parameters: timeout (int) – timeout for server verification
-
class_logger= <logging.LoggerAdapter object>¶
-
launch_server(port=None)[source]¶ Launch xmlrpc server.
Parameters: port (int) – port to launch xmlrpc server
-
pytest_keyboard_interrupt(excinfo)[source]¶ Handle KeyboardInterrupt.
Parameters: excinfo (py.code.ExceptionInfo) – exception info
-
pytest_runtest_call(item)[source]¶ Create TC instance and send it to the Reporting Server.
Parameters: item (pytest.Item) – test case item
-
pytest_runtest_logreport(report)[source]¶ Send update TC run status to the Reporting Server.
Parameters: report (pytest.BaseReport) – pytets report
-
pytest_runtest_setup(item)[source]¶ Add info about test case start time.
Parameters: item (pytest.Item) – test case item
-
pytest_sessionfinish(session)[source]¶ Tell to XMLRPC Server that we have finished interaction.
Parameters: session (pytest.Session) – test session
-
-
class
taf.plugins.pytest_reportingserver.ReportingServerConfigBase[source]¶ Bases:
objectReporting Server configuration.
-
taf.plugins.pytest_reportingserver.imp_plugins(dest)[source]¶ Import all py modules from <dest> subfolder.
taf.plugins.pytest_returns¶
pytest_returns.py
Collect return results from testcases instead of ‘PASSED’ message
-
class
taf.plugins.pytest_returns.ReturnsPlugin[source]¶ Bases:
object-
PYTEST_REPORT_STATUSES= {'failed': {'letter': 'F', 'msg': 'FAILED', 'outcome': 'failed'}, 'passed': {'letter': 'P', 'msg': 'PASSED', 'outcome': 'passed'}, 'skipped': {'letter': 'S', 'msg': 'SKIPPED', 'outcome': 'skipped'}}¶
-
REPORT_RESULT_GETTER= operator.itemgetter('outcome', 'letter', 'msg')¶
-
RESULT_FAILED= 'failed'¶
-
RESULT_PASSED= 'passed'¶
-
RESULT_SKIPPED= 'skipped'¶
-
taf.plugins.pytest_skip_filter¶
taf.plugins.pytest_smartrerun¶
taf.plugins.pytest_start_from_case¶
pytest_start_from_case.py
Starting tests execution from the specified test case not from the beginning
Examples:
# complete test-name
$ py.test PATH_TO_TESTS --start_from_case test_my_func
# not complete test-name
$ py.test PATH_TO_TESTS --start_from_case test*func
# or
$ py.test PATH_TO_TESTS --start_from_case *func
# parameterized tests
$ py.test PATH_TO_TESTS --start_from_case test*[1]
# or
$ py.test PATH_TO_TESTS --start_from_case test*1
taf.plugins.pytest_sut_monitor¶
taf.plugins.pytest_syslog¶
pytest_syslog.py
Plugin writes messages to SysLogHandler
Note
For correct functioning syslog should be properly configured, e.g.
On device should be configured hostname seacliff9.
The following lines should be added to syslog config:
# This is criteria for seacliff messages if $hostname contains 'seacliff9' then /var/log/switches/seacliff09.log # This s criteria for our log messages if $msg contains 'seacliff9' and $programname == 'pytest_syslog' then /var/log/switches/seacliff9.log
Also it is good to configure logrotate (e.g. /etc/logrotate.d/switches) file of :
Examples:
/var/log/switches/*.log
{
rotate 730
weekly
missingok
notifempty
delaycompress
compress
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
- Known issues:
- rsyslog could miss log messages from remote host if it cannot resolve host FQDN 10 times. To disable dns resolving add -x option to /etc/default/rsyslog (for debian based distros).
-
class
taf.plugins.pytest_syslog.SyslogNotifier[source]¶ Bases:
objectSend syslog messages.
-
_create_header(env_prop, stage)[source]¶ Send syslog header/footer message for each device in config.
Parameters: Returns: None
Examples:
self._create_header(env_object.config, {"py.test PID": "5216", "chipName": "8086", "cpuArchitecture": "8bit"}, "SessionStart")
-
_update_tc_status(tcname, status)[source]¶ Send syslog TC status message for each device in config.
Parameters: Returns: None
Examples:
self._update_tc_status(env_object.config, "test_some_feature_1", "started")
-
get_last_record_from_log(log, item)[source]¶ Return last log records for TC.
Parameters: - log (str) – log file
- item (pytest.Item) – test case item
Returns: Log related to specified test item
Return type:
-
get_log_path(switch_name)[source]¶ Return log path from environment.json for switch.
Parameters: switch_name (str) – switch name Returns: path to log for specified device Return type: str
-
is_test_completed(report)[source]¶ Return True if make_report hook called after TC and TC failed.
Parameters: report (pytest.Report) – pytest report Returns: True if test is complited without errors Return type: bool
-
taf.plugins.pytest_test_duration¶
pytest_test_duration.py
Plugin is controlling test execution by time or count of iteration
-
class
taf.plugins.pytest_test_duration.Duration(option=None)[source]¶ Bases:
objectMain functionality for test duration manipulation.
-
__init__(option=None)[source]¶ Initialize Duration object instance.
Parameters: option (str, e.g "30s", "2.5H") – time to interrupt test(cmd option)
-
taf.plugins.pytest_workload¶
taf.plugins.reports_conf¶
taf.plugins.reports_conf¶
taf.plugins.reports_conf.SYNAPSERT¶
SYNAPSERT.py
SYNAPSERT class
-
class
taf.plugins.reports_conf.SYNAPSERT.ReportingServerConfig[source]¶ Bases:
objectReporting Server configuration.
-
static
_configure(config)[source]¶ Checking tm_update option.
Parameters: config (bool) – get options
-
static
_get_build_name(options)[source]¶ Return spesified buildname.
Parameters: options (str) – get options
-
static
_sessionstart(log_class, item, name, buildname)[source]¶ Tell to XMLRPC Server that we are going to interact with it.
Parameters:
-
class_logger= <logging.LoggerAdapter object>¶
-
static
taf.plugins.reports_conf.XML¶
XML.py
XML and HTML report classes