Skip to main content

Multi-process logs handling and other helpers for pytest

Project description

pytest-multilog

A pytest plugin to persist logs from parallel test processes (and other helpers)

License: MPL Checks Issues Supported python versions PyPI Code style: black Flake8 analysis result Code coverage

Usage

To use the multilog feature, a test class just needs to inherit from the TestHelper class:

from pytest_multilog import TestHelper

class TestCustom(TestHelper):
    def test_custom(self):
        # Custom test implementation
        ...

The TestHelper class declares a logs fixture which will be automatically used by its children classes.

Behavior and attributes

Root folder

The TestHelper class provides a root_folder property, matching with the pytest root folder.

Output folder

The TestHelper class provides a output_folder property, where all files will be written. It's set to output_folder / "out" / "tests"

Test name

Each test is associated to a name (provided in TestHelper.test_name), computed from the file name, the class name and the method name.

E.g. for the snippet above, if stored in a test_custom.py file, the test name will be: test_custom_TestCustom_test_custom.

Current worker

In multi-process environment (pytest was invoked with -n X argument), the current worker name is provided in TestHelper.worker attribute. It's set to "master" in single-process environment.

The class also provides a TestHelper.worker_index attribute, giving the working index as an integer value (will be set to 0 for "master").

Test folder

Test logs will be written in a pytest.log file (path provided in TestHelper.test_logs), stored in each test folder (provided in TestHelper.test_folder attribute):

  • While the test is running, it's set to TestHelper.output_root / "__running__" / TestHelper.worker / TestHelper.test_name
  • Once the test is terminated, the folder is moved directly under the output root one.

It means that during the test execution, it's possible to check which test is running on which worker (easing troubleshooting situations where a given worker is blocked)

Checking logs

It is possible to verify if some strings are present in the current test log, by using the TestHelper.check_logs method. It takes as input argument:

  • either a simple string/Pattern or a list of strings/Patterns:
    • strings will be simply checked to be contained in the whole log
    • Patterns will be searched line by line (more flexible, but slower)
  • an optional timeout
  • a check_order parameter to verify patterns order (default if False)

The method will assert if all inputs are found in the log (within the expected timeout, if any).

By default, expected patterns order doesn't matter. If check_order parameter is set to True, patterns will be expected in the input order, and check will fail if the order doesn't match.

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-multilog-1.4.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

pytest_multilog-1.4.2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file pytest-multilog-1.4.2.tar.gz.

File metadata

  • Download URL: pytest-multilog-1.4.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for pytest-multilog-1.4.2.tar.gz
Algorithm Hash digest
SHA256 0ccea0488cf4f1f5638454081ca076f733428303134bf8d8ce319a86eb834731
MD5 d646d9d073a1f1a43f38c5e6f86f4d61
BLAKE2b-256 525517e06cfb42dab3efb6b8914aa08df2fd87405fa1183a8e977ed3a097b52f

See more details on using hashes here.

File details

Details for the file pytest_multilog-1.4.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_multilog-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7b942b52f3031facf326e7d57bf0813b09e2724a143b610195ed3c4d5526f709
MD5 b016455611eaeab6ef3a5e34d8cb34ab
BLAKE2b-256 10d2e8be0762239fb9d0b2525321fc6f9b64aa55d5429fce9bbb5040d3a2399f

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