Skip to main content

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

Project description

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


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

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


  • Pytest

  • Pathlib2 (if using Python 2.7)


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

$ pip install pytest-logfest



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: < | 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).


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

  • 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


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.


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


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


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


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.

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-logfest-0.3.0.tar.gz (6.7 kB view hashes)

Uploaded Source

Built Distributions

pytest_logfest-0.3.0-py3-none-any.whl (9.5 kB view hashes)

Uploaded Python 3

pytest_logfest-0.3.0-py2-none-any.whl (9.5 kB view hashes)

Uploaded Python 2

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