Skip to main content

PyTest plugin for generating Difido reports

Project description

pytest-difido


PyTest plugin for creating flexible and informative test reports


This pytest plugin was generated with Cookiecutter along with @hackebrot’s cookiecutter-pytest-plugin template.

Features


  • Flexible locally generated HTML report on the running machine

  • Reports are generated at runtime. No need to wait for test execution to end

  • Easily attach files and images to the report

  • Works also in remote mode. You can add Difido server that allows publishing reports to central server

  • Console reports - Reports to the console in addition to the HTML output mainly for development phase and CI/CD systems

  • Extensible - Allows to implement and add additional reporters

Requirements


  • PyTest >= 4.0.0

  • Python >= 3

Installation


You can install “pytest-difido” via pip from PyPI:

$ pip install pytest-difido

Usage


To use the report, add the report fixture to your test cases. You can report simple message, links, HTML elements and more

def test_messaging(report):

    # Simple message will be added to the report

    report.that("Simple report message")

    # link to Google

    report.link(title='Google', link=r'http:\\www.google.com')



    # Message will be hidden inside toggle element

    report.start_level("start toggle")

    report.that("In toggle")

    report.stop_level()



    # Message will appear in bold font

    report.step("bold message")



    # HTML element will be added to the report

    report.html("Table", """

        <table>

      <tr>

        <th>Company</th>

        <th>Contact</th>

      </tr>

      <tr>

        <td>ACME Corporation</td>

        <td>Road Bumper</td>

      </tr>

      <tr>

        <td>DOLO Inc</td>

        <td>Wired Coyote</td>

      </tr>

    </table>

        """)

Files and images can be attached to the HTML report. The files are copied to the local and remote reports.

def test_files(report):

    # File will be copied and attached to the report

    report.file(file_path=os.path.join("resources", "some_file.txt"), description="My text file")

    # Image will added with thumbnail

    report.img(img_path=os.path.join("resources", "cat.jpg"), description="Cats are awesome")

Properties can be added to the suite or to each test. The properties are disaplyed in the report and, if ElasticSearch integration is enabled, can be searched.

def test_add_properties(report):

    # Property will be added to the execution

    report.add_execution_properties("int_Execution", "66")



    # Property will be added to the current running test

    report.add_test_property("double_testProp", "1.56")

If you prefer to use to report without fixtures, or if you want to use it from places other then your test cases, you can intantiate the Report class.

The ‘Report’ class is implemented as singleton so you will always get the same instance

def test_report_without_fixture():

    """

    If you don't want to get the reporter as fixture or if you want to use it not from test method

    you can just instantiate the Report class. The Report class is implemented as Singleton

    """

    from difido.report_manager import Report

    report = Report()

    report.that("very important message")

Server Installation


This step is not mandatory. Local reports will be generated also without the Difido server. Follow this step only if you wish to

have central server for publishing test results. If all you need is local reports that will be generated on the running machine, skip this step

  • Download the latest Difido server ZIP file from the Difido releases page

  • Extract the content of the file

  • Run the ‘[root]/bin/start.bat’ or ‘[root]/bin/start.sh’ file according to your OS.

  • Set the host and port in the client configuration as shown in the next section

  • Add the ‘difido.reporters.RemoteReporter’ to the ‘df_reporters’ list in the configuration. More information about reporters can be found in the ‘Reporters’ section

You can access the server from your browser (E.G http://localhost:8080/). For more information please refer to the Difido server Wiki page

Configuration


You can configure the reporter from the pytest.ini file or from the command line.

In the case where a parameter is defined using both methods, the value defined from the command line takes precedence

pytest.ini examples

[pytest]

; Host or ip of Difido server. Default localhost

df_host = 192.168.0.13

; Port of Difido server. Default 8080

df_port = 8090

; Result folder for HTML and console reports. Default is current directory

df_output_folder = /etc/log/

; Reporters are defined in the following comma-separated list

df_reporters = difido.reporters.LocalReporter,difido.reporters.RemoteReporter,difido.reporters.ConsoleReporter

Command line example

$ pytest .\tests\test_report_examples.py --df_host=192.168.10.1 --df_port=8090

Configuration Properties

  • df_output_folder - Result folder for HTML and console reports (default .)

  • df_host - Host or ip of Difido server (default localhost)

  • df_port - Difido server port (default 8080)

  • df_reporters - Comma-separated list of reporter classes. The all reporters recieves the event from the report manager

  • df_description - Description of test execution as shown in the Difido server

Reporters


Reporters are Python classes that translates the events recieved from the tests and generates a single report format.

The plugin currently includes three types of reporters:

  • difido.reporters.LocalReporter - Generates local HTML reports to the repors output folder

  • difido.reporters.RemoteReporter - Pulishes results to the Difido server

  • difido.reporters.ConsoleReporter - Writes to the conole. At the end of the run the output is also copied to a file in the reports output folder.

You can decide which reporters you want to enabled by adding or removing the classes from the ‘df_reporters’ list.

By default, only the ‘LocalReporter’ and ‘ConsoleReporter’ are included in the list. To use the remote reporter, for example, you will need to add it by configuring the ‘df_reporters’ as following:

df_reporters = difido.reporters.LocalReporter,difido.reporters.RemoteReporter,difido.reporters.ConsoleReporter

You can also implement your own reporter and add it to the list.

Contributing


Contributions are very welcome. Tests can be run with tox, please ensure

the coverage at least stays the same before you submit a pull request.

License


Distributed under the terms of the Apache Software License 2.0 license, “pytest-difido” is free and open source software

Issues


If you encounter any problems, please file an issue along with a detailed description.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-difido-0.5.1.tar.gz (293.7 kB view details)

Uploaded Source

Built Distribution

pytest_difido-0.5.1-py3-none-any.whl (291.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest-difido-0.5.1.tar.gz.

File metadata

  • Download URL: pytest-difido-0.5.1.tar.gz
  • Upload date:
  • Size: 293.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.5

File hashes

Hashes for pytest-difido-0.5.1.tar.gz
Algorithm Hash digest
SHA256 b602c008b93e823608af3907b7c6fe8e99a9fcbde21e5db6a2661c4d52c656ef
MD5 b18356e7c15cbccb26fc84e4963b35b4
BLAKE2b-256 ae92dc1073814ded80acc4d2dd1f9b9f78760875ef3b83cd70a53875d0971c66

See more details on using hashes here.

File details

Details for the file pytest_difido-0.5.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_difido-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 538d411fade9617f347307ffd5f67ca6f13dffe77534af613ad87adbd399d5f4
MD5 d312c89dfb1c456e70ab4c73bce906e3
BLAKE2b-256 1840ffd2e36b68cac950b4faf851876ebf8e4fb714067bc2bc1318381b3d9663

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page