4.1. qa_analytics_insights package

4.1.1. Submodules

4.1.2. qa_analytics_insights.cli module

Copyright (c) 2023, Aydin Abdi.

Command line interface for the qa-analytics-insights package.

class qa_analytics_insights.cli.ArgsParser[source]

Bases: object

Class for handling command line arguments.

add_arguments() ArgumentParser[source]

Add command line arguments.

property args: Namespace

Return the parsed arguments.

Returns:

Namespace object.

help() None[source]

Print help message.

property parser: ArgumentParser

Return the parser object.

Returns:

ArgumentParser object.

usage() None[source]

Print usage message.

class qa_analytics_insights.cli.Cli[source]

Bases: object

Class for handling command line interface.

cli_main(args: List[str] | None = None) None[source]

Main method for the command line interface.

Parameters:

args – Command line arguments.

run(file_path: str, output: str = 'test_results_visualization') None[source]

Main execution method.

qa_analytics_insights.cli.main(args: List[str] | None = None) None[source]

Main method for the command line interface.

Parameters:

args – Command line arguments.

4.1.3. qa_analytics_insights.data_classes module

Copyright (c) 2023, Aydin Abdi.

This file contains the data classes used in the qa-analytics-insights package.

class qa_analytics_insights.data_classes.TestCase(name: str, test_module: str | None = None, test_class: str | None = None, execution_time: float = 0.0, result: str = 'passed', timestamp: str | None = None, failure_reason: str | None = None, error_reason: str | None = None, skipped_reason: str | None = None, system_out: str | None = None)[source]

Bases: object

Represents a test case.

Parameters:
  • name – Name of the test case.

  • test_module – Name of the test module.

  • test_class – Name of the test class.

  • execution_time – Execution time of the test case.

  • result – Result of the test case.

  • timestamp – Timestamp of the test case.

  • failure_reason – Failure reason of the test case.

  • skipped_reason – Skipped reason of the test case.

  • system_out – System out of the test case.

error_reason: str | None = None
execution_time: float = 0.0
failure_reason: str | None = None
name: str
result: str = 'passed'
skipped_reason: str | None = None
system_out: str | None = None
test_class: str | None = None
test_module: str | None = None
timestamp: str | None = None
class qa_analytics_insights.data_classes.TestClass(name: str, test_cases: ~typing.List[~qa_analytics_insights.data_classes.TestCase] = <factory>)[source]

Bases: object

Represents a test class.

Parameters:
  • name – Name of the test class.

  • test_cases – List of test cases in the test class.

  • passed – Number of passed tests in the test class.

  • failed – Number of failed tests in the test class.

  • skipped – Number of skipped tests in the test class.

  • errors – Number of errors in the test class.

  • execution_time – Execution time of the test class.

  • failed_test_cases – List of failed test cases in the test class.

  • skipped_test_cases – List of skipped test cases in the test class.

  • error_test_cases – List of error test cases in the test class.

error_test_cases: List[TestCase]
errors: int = 0
execution_time: float = 0.0
failed: int = 0
failed_test_cases: List[TestCase]
name: str
passed: int = 0
skipped: int = 0
skipped_test_cases: List[TestCase]
test_cases: List[TestCase]
class qa_analytics_insights.data_classes.TestSuite(name: str | None = None, tests: int = 0, errors: int = 0, failures: int = 0, skipped: int = 0, execution_time: float = 0.0, timestamp: str | None = None, test_classes: ~typing.List[~qa_analytics_insights.data_classes.TestClass] = <factory>, test_cases: ~typing.List[~qa_analytics_insights.data_classes.TestCase] = <factory>)[source]

Bases: object

Represents a test suite.

Parameters:
  • name – Name of the test suite.

  • tests – Total number of tests.

  • errors – Total number of errors.

  • failures – Total number of failures.

  • skipped – Total number of skipped tests.

  • execution_time – Total execution time of the test suite.

  • timestamp – Timestamp of the test suite.

  • test_classes – List of test classes in the test suite.

  • test_cases – List of ungrouped test cases in the test suite.

  • passed – Number of passed tests in the test suite.

errors: int = 0
execution_time: float = 0.0
failures: int = 0
name: str | None = None
passed: int = 0
skipped: int = 0
test_cases: List[TestCase]
test_classes: List[TestClass]
tests: int = 0
timestamp: str | None = None

4.1.4. qa_analytics_insights.log module

Copyright (c) 2023, Aydin Abdi.

This module is responsible for logging.

qa_analytics_insights.log.default_logging() None[source]

loguru default.

qa_analytics_insights.log.log_execution_time(method: Callable[[...], Any]) Callable[[...], Any][source]

Decorator to log the time execution of a method.

Parameters:

method – The method to be decorated.

Returns:

The decorated method.

qa_analytics_insights.log.verbose_logging() None[source]

loguru verbose.

4.1.5. qa_analytics_insights.parser module

Copyright (c) 2023, Aydin Abdi.

This module is responsible for parsing test cases from XML tags.

class qa_analytics_insights.parser.ParserTestCase(test_case: Element)[source]

Bases: object

Responsible for parsing TestCase objects from XML tags.

find_tag_attribute(tag: str, attrib: str | None = None) str | None[source]

Find the tag for test case element and return the attribute or text.

Parameters:
  • tag – Tag to parse.

  • attrib – Attribute to parse. If None, the tag text is returned.

Returns:

Find the tag and return the attribute or text.

get_failure_reason(tag: str = 'failure') str | None[source]

Parse the failure reason from a failure tag.

Parameters:

tag – XML element representing a failure tag. Defaults to “failure”.

Returns:

Failure reason.

get_skipped_reason(tag: str = 'skipped') str | None[source]

Parse the skipped reason from a skipped tag.

Parameters:

tag – XML element representing a skipped tag. Defaults to “skipped”.

Returns:

Skipped reason.

get_system_out(tag: str = 'system-out') str | None[source]

Parse the system out from a system-out tag.

Parameters:

tag – Tag to parse.

Returns:

System out or None if no system out is found.

get_testcase_result() str[source]

Parses the test case result from the test case tag.

Returns:

Test case result.

get_timestamp(tag: str = 'system-out') str | None[source]

Parse the timestamp from a system-out tag or timestamp tag.

Parameters:

tag – XML element representing a system-out tag. Defaults to “system-out”.

Returns:

Timestamp or None if no timestamp is found.

parse() TestCase[source]

Parses the XML tag into TestCase object.

Returns:

TestCase object.

class qa_analytics_insights.parser.ParserTestSuite(test_suite: Element)[source]

Bases: object

Responsible for parsing TestSuite objects from XML tags.

parse() TestSuite[source]

Parses the XML tag into TestSuite object.

Returns:

TestSuite object.

4.1.6. qa_analytics_insights.patch_fetcher module

Copyright (c) 2023, Aydin Abdi.

This module is responsible for fetching paths from the given initial path.

class qa_analytics_insights.patch_fetcher.PathFetcher(initial_path: str)[source]

Bases: object

Responsible for fetching paths from the given initial path.

Example

PathFetcher(initial_path=’path/to/initial/path’)

fetch_paths() Queue[Path][source]

Fetches paths from the given initial path.

Returns:

Queue of paths.

4.1.7. qa_analytics_insights.result_analyzer module

Copyright (c) 2023, Aydin Abdi.

ResultAnalyzer implements the logic for analyzing the test results with different metrics which can be used to visualize the results.

class qa_analytics_insights.result_analyzer.ResultAnalyzer(path: str, num_threads: int = 10)[source]

Bases: object

Analyzes the test results with several metrics.

Example

  • slowest_test_classes

  • slowest_test_cases

  • failed_test_cases with failure_reason

  • skipped_test_cases with skipped_reason

  • execution times by test class in descending order

property classes: List[TestClass]

Return the test classes.

Returns:

List of TestClass objects.

get_execution_times_by_test_class_in_descending_order() List[TestClass][source]

Return the test classes sorted by execution time in descending order.

Returns:

List of TestClass objects.

get_slowest_test_classes(num_test_classes: int = 10) List[TestClass][source]

Return the slowest test classes.

Parameters:

num_test_classes – Number of test classes to return.

Returns:

List of TestClass objects.

process_test_results() None[source]

Process the test result XML files and parse them into TestClass objects.

Returns:

List of TestSuites objects.

property suites: List[TestSuite]

Return the test suites.

Returns:

List of TestSuite objects.

property test_cases: List[TestCase]

Return the test cases for all test suites.

Ungrouped test cases are also included.

Returns:

List of TestCase objects.

4.1.8. qa_analytics_insights.result_visualizer module

Copyright (c) 2023, Aydin Abdi.

This module is responsible for visualizing the results of the parsed TestClass objects.

class qa_analytics_insights.result_visualizer.ParallelResultVisualizer(test_suites: List[TestSuite] | None = None)[source]

Bases: ResultVisualizer

Class to visualize the results of the parsed TestClass objects in parallel.

generate_html_plots(output: str, slowest_test_classes: List[TestClass] | None = None) None[source]

Main execution method.

Parameters:
  • output – Output file name.

  • slowest_test_classes – List of the slowest test classes.

class qa_analytics_insights.result_visualizer.ResultVisualizer(test_suites: List[TestSuite] | None = None)[source]

Bases: object

Class for visualizing test results.

build_subplots_failed_table() str | None[source]

Plot a table of failed test cases.

Returns:

The base64 encoded string representation of the figure.

build_subplots_pie_chart_test_classes_results() str | None[source]

Plot the results of the parsed TestClass objects.

Returns:

The base64 encoded string representation of the figure.

build_subplots_skipped_table() str | None[source]

Plot a table of skipped test cases.

Returns:

The base64 encoded string representation of the figure.

build_subplots_test_suites_summary_table() str | None[source]

Plot a table of test suites summary.

Returns:

The base64 encoded string representation of the figure.

build_subplots_top_slowest_test_classes(slowest_test_classes: List[TestClass]) str | None[source]

Plot a pie bar chart of the top slowest test classes.

Parameters:

slowest_test_classes – List of the slowest test classes.

Returns:

The base64 encoded string representation of the figure.

static figure_to_base64(figure: Figure) str[source]

Convert a Matplotlib figure to a base64 string.

Parameters:

figure – The figure to convert.

Returns:

The base64 encoded string representation of the figure.

static generate_html_report_to_file(output: str, pie_charts: str | None = None, failed_table: str | None = None, skipped_table: str | None = None, summary_table: str | None = None, slowest_classes: str | None = None) None[source]

Generate an HTML report of the test results.

Parameters:
  • pie_charts – Base64 string representing the pie charts.

  • failed_table – Base64 string representing the failed test cases table.

  • skipped_table – Base64 string representing the skipped test cases table.

  • summary_table – Base64 string representing the test suites summary table.

  • slowest_classes – Base64 string representing the top slowest test classes.

  • output – Output file name.

plot_failed_test_cases_table() Figure | None[source]

Plot a table of failed/error test cases.

Returns:

The figure for failed/error test cases table.

plot_pie_charts_test_classes() Figure | None[source]

Plot pie charts for each test class.

Returns:

Figure containing the pie charts.

plot_skipped_test_cases_table() Figure | None[source]

Plot a table of skipped test cases.

Returns:

The figure for skipped test cases table.

plot_test_suites_summary_table() Figure | None[source]

Plot a table of test suites summary.

Returns:

The figure for test suites summary table.

plot_top_slowest_test_classes_pie_bar_chart(slowest_test_classes: List[TestClass] | None = None) Figure | None[source]

Plot a pie bar chart of the top slowest test classes.

Parameters:

slowest_test_classes – List of the slowest test classes.

Returns:

The figure for the top slowest test classes pie bar chart.

run(output: str = 'test_results_visualization', pie_charts: Figure | None = None, failed_table: Figure | None = None, skipped_table: Figure | None = None, summary_table: Figure | None = None, slowest_classes: List[TestClass] | None = None) None[source]

Main execution method.

Parameters:
  • output – Output file name.

  • pie_charts – Figure containing the pie charts.

  • failed_table – Figure containing the failed test cases table.

  • skipped_table – Figure containing the skipped test cases table.

  • slowest_classes – List of the slowest test classes.

  • summary_table – Figure containing the test suites summary table.

property test_cases: List[TestCase]

Return the test cases.

Returns:

List of TestCase objects.

property test_classes: List[TestClass]

Return the test classes.

Returns:

List of TestClass objects.

static truncate_name(name: str | None, max_length: int = 16) str[source]

Truncate long names to prevent visualization overflow.

Parameters:
  • name – The name to truncate. Can be None.

  • max_length – Maximum allowed length (default: 16).

Returns:

Truncated name with ellipsis if it was too long.

4.1.9. qa_analytics_insights.xml_filter module

Copyright (c) 2023, Aydin Abdi.

This module filters XML files from the given path queue.

class qa_analytics_insights.xml_filter.XMLFilter(path_queue: Queue[Path])[source]

Bases: object

Responsible for filtering XML files from the given path queue.

filter_xml() Queue[Path][source]

Filters XML files from the given path queue.

Returns:

Queue of XML files.

4.1.10. qa_analytics_insights.xml_loader module

Copyright (c) 2023, Aydin Abdi.

This module is responsible for loading XML files.

class qa_analytics_insights.xml_loader.XMLLoader(xml_path: str)[source]

Bases: object

Responsible for loading XML file.

property root: Element

Returns the XML root.

Returns:

XML root.

property tree: ElementTree

Returns the XML tree.

Returns:

XML tree.

4.1.11. qa_analytics_insights.xml_parser module

Copyright (c) 2023, Aydin Abdi.

This module is responsible for parsing XML files into TestSuite objects.

class qa_analytics_insights.xml_parser.XMLParser(xml_tag_finder: XMLTagFinder)[source]

Bases: object

Responsible for parsing XML files into TestClass and TestCase objects.

parse() TestSuite[source]

Parses the XML file into TestClass and TestCase objects.

This method parses test cases and groups them by their class name. If a test case has no class name,it will be added to the ungrouped_test_cases list.

Returns:

TestSuite object.

4.1.12. qa_analytics_insights.xml_processor module

Copyright (c) 2023, Aydin Abdi.

This module processes files in the given path in parallel and puts the xml files in a queue for further processing.

class qa_analytics_insights.xml_processor.XMLProcessor(path: str)[source]

Bases: object

Responsible for processing files into xml queues.

Parameters:

path – Path to the XML files.

process_files_in_parallel(num_threads: int) None[source]

Processes the XML files in the given path in parallel.

Parameters:

num_threads – Number of threads to use for processing.

4.1.13. qa_analytics_insights.xml_tag_finder module

Copyright (c) 2023, Aydin Abdi.

This module is responsible for finding XML tags in XML files.

class qa_analytics_insights.xml_tag_finder.XMLTagFinder(xml_loader: XMLLoader)[source]

Bases: object

Responsible for finding XML tags in XML files.

property suite: Element

Returns the suite element.

This method returns the testsuite element if it exists. If the testsuite element does not exist, it returns the root element.

Returns:

Suite element.

property test_cases: List[Element]

Returns all the testcase tags in the XML file.

Returns:

List of testcase tags.

4.1.14. Module contents

Copyright (c) 2023, Aydin Abdi.

This module is analyze and extracts the data from test results and can visualize the data in different ways.