Skip to main content
PyPI version Python versions See Build Status on Travis CI See Build Status on AppVeyor MIT license

Pytest plugin providing three logger fixtures with basic or full writing to log files


Features

Three logger fixtures, one of each scope: session, module and function.

Three options for writing log records to file: quiet, basic, full.

Requirements

  • Pytest

  • Pathlib2 (if using Python 2.7)

Installation

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

$ pip install pytest-logfest

Usage

Fixtures

The three logger fixtures exposed by this plugin are:

  • session_logger

  • module_logger

  • function_logger

They expose a Python Logger object, so you can use them as such, e.g. session_logger.INFO("This is a log record of level INFO.") The log nodes of these loggers match the path to the corresponding location or file.

Pytest’s --log-cli-level=<level> will display these log records on stdout.

Log filenames

Writing the log records of the loggers to file can be controlled by the --logfest command-line option:

  • --logfest=quiet or option omitted: no log files are written.

  • --logfest=basic: one log file containing INFO and higher for passed tests, DEBUG and higher for setup errors or failed tests.

  • --logfest=full: in addition to the basic log file, all log records are written to a session log file and one log file per module.

Log file names and locations are as follows (directories will be created if needed):

  • basic log file in ./artifacts: session-<session timestmap>.log

  • session-level full log file in ./artifacts: <request.node.name | logfest-root-node>-<session timestmap>.log

  • module-level full log file in ./artifacts/<path-to-module>: <module_name>-<session timestmap>.log

logfest-root-node can be set in pytest.ini (see below). You can change the compostion of file names through hooks (see below).

pytest.ini

The following values in pytest.ini are relevant to this plugin:

  • logfest-root-node: name used as root log node and in log filenames; if not set, defaults to the session’s request.node.name.

  • log-level: should be set to info or lower, so pytest captures all relevant log records.

  • log-format: the default format is not very convenient in combination with this plugin, suggestion: %(name)s - %(levelname)s - %(message)s

Hooks

There are three hooks to change the components of the log filenames:

  • pytest_logfest_log_file_name_basic

  • pytest_logfest_log_file_name_full_session

  • pytest_logfest_log_file_name_full_module

The expose a list that will be joined with the separator character - and appended with .log.

Contributing

Contributions are very welcome. Tests can be run with tox, please ensure good test coverage before you submit a pull request.

License

Distributed under the terms of the MIT license, “pytest-logfest” is free and open source software.

Issues

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

Acknowledgements

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

Thanks to my employer Mendix, for the crafting days in which I worked on this plugin, and for the permission to open-source it.

Release files for pytest-logfest 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-logfest 0.3.0
File Size Uploaded
pytest-logfest-0.3.0.tar.gz 6.7 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pytest-logfest 0.3.0
File Interpreter ABI Platform
pytest_logfest-0.3.0-py3-none-any.whl Python 3 none any Details
pytest_logfest-0.3.0-py2-none-any.whl Python 2 none any Details

Total release size: 25.7 kB

Release files / pytest-logfest-0.3.0.tar.gz

Download URL pytest-logfest-0.3.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
71ca50517c523fbbc81728b1353afd58703d1b894bbc63aeb77f4ee45b38728a
BLAKE2b-256 checksum
How to use checksums
baea684417ca2536a50fa1491b5b812091cea8548c98f69c5b9e29616e033356
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.22.0 CPython/2.7.15+

Release files / pytest_logfest-0.3.0-py3-none-any.whl

Download URL pytest_logfest-0.3.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5534ba712ac253f64a5499e2e67db736611c242162999205d917eb23cb5efa64
BLAKE2b-256 checksum
How to use checksums
5c7c08247d553287fe70016363a3e38df26321f3610fe817c7ff58d0cfae2282
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.22.0 CPython/2.7.15+

Release files / pytest_logfest-0.3.0-py2-none-any.whl

Download URL pytest_logfest-0.3.0-py2-none-any.whl
Size 9.5 kB
Tags Python 2
SHA-256 checksum
How to use checksums
7322a3e16deb06a83050e9c3d839ddde66d17ca2d89d8417f89916f2dc9831aa
BLAKE2b-256 checksum
How to use checksums
0898ac69cff0df0a113e587deed57b9fe434df211546e7420d58242a85835708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.22.0 CPython/2.7.15+

Release history Release notifications | RSS feed

This release

0.3.0 This release

3 release files

0.2.0

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page