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


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.

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 details)

Uploaded Source

Built Distributions

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

Uploaded Python 3

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

Uploaded Python 2

File details

Details for the file pytest-logfest-0.3.0.tar.gz.

File metadata

  • Download URL: pytest-logfest-0.3.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using 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+

File hashes

Hashes for pytest-logfest-0.3.0.tar.gz
Algorithm Hash digest
SHA256 71ca50517c523fbbc81728b1353afd58703d1b894bbc63aeb77f4ee45b38728a
MD5 8a2abda154677bc35da3f56d09b0a598
BLAKE2b-256 baea684417ca2536a50fa1491b5b812091cea8548c98f69c5b9e29616e033356

See more details on using hashes here.

File details

Details for the file pytest_logfest-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_logfest-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using 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+

File hashes

Hashes for pytest_logfest-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5534ba712ac253f64a5499e2e67db736611c242162999205d917eb23cb5efa64
MD5 923f673a5617f10d7d366a22c8ff83d4
BLAKE2b-256 5c7c08247d553287fe70016363a3e38df26321f3610fe817c7ff58d0cfae2282

See more details on using hashes here.

File details

Details for the file pytest_logfest-0.3.0-py2-none-any.whl.

File metadata

  • Download URL: pytest_logfest-0.3.0-py2-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 2
  • Uploaded using 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+

File hashes

Hashes for pytest_logfest-0.3.0-py2-none-any.whl
Algorithm Hash digest
SHA256 7322a3e16deb06a83050e9c3d839ddde66d17ca2d89d8417f89916f2dc9831aa
MD5 6ac4aea035a94704b0c0b2498731e321
BLAKE2b-256 0898ac69cff0df0a113e587deed57b9fe434df211546e7420d58242a85835708

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