Plugin configuring handlers for loggers from Python logging module.
Project description
Pytest-logger is a pytest plugin configuring handlers for loggers from Python logging module.
You can install pytest-logger via pip from PyPI:
$ [sudo] pip install pytest-logger
Plugin puts logs on per-logger basis to:
standard output,
files within log-specific directory under pytest’s tmpdir_factory session directory.
You can setup plugin using hook:
#conftest.py import os def pytest_logger_config(logger_config): logger_config.add_loggers(['foo', 'bar', 'baz'], stdout_level='info') logger_config.set_log_option_default('foo,bar') def pytest_logger_logdirlink(config): return os.path.join(os.path.dirname(__file__), 'mylogs')
have logging tests or libraries (including fixtures):
#test_something.py import pytest import logging foo = logging.getLogger('foo') bar = logging.getLogger('bar') baz = logging.getLogger('baz') @pytest.yield_fixture(scope='session') def session_thing(): foo.debug('constructing session thing') yield foo.debug('destroying session thing') @pytest.yield_fixture def testcase_thing(): foo.debug('constructing testcase thing') yield foo.debug('destroying testcase thing') def test_one(session_thing, testcase_thing): foo.info('one executes') bar.warning('this test does nothing aside from logging') baz.info('extra log, rarely read') def test_two(session_thing, testcase_thing): foo.info('two executes') bar.warning('neither does this') baz.info('extra log, not enabled by default')
and expect output in terminal (if not captured):
$ py.test -s -v (...) test_something.py::test_one 00:00.002 inf foo: one executes 00:00.002 wrn bar: this test does nothing aside from logging PASSED test_something.py::test_two 00:00.000 inf foo: two executes 00:00.000 wrn bar: neither does this PASSED
being able to change this output by cmdline option:
$ pytest -s -v --log foo.debug,baz (...) test_something.py::test_one 00:00.002 dbg foo: constructing session thing 00:00.002 dbg foo: constructing testcase thing 00:00.002 inf foo: one executes 00:00.003 inf baz: extra log, rarely read PASSED test_something.py::test_two 00:00.000 dbg foo: constructing testcase thing 00:00.000 inf foo: two executes 00:00.001 inf baz: extra log, not enabled by default PASSED
and - the same - in filesystem:
$ file mylogs mylogs: symbolic link to `/tmp/pytest-of-aurzenligl/pytest-48/logs' $ tree mylogs mylogs `-- test_something.py |-- test_one | |-- bar | |-- baz | `-- foo `-- test_two |-- bar |-- baz `-- foo
Distributed under the terms of the MIT license, pytest-logger is free and open source software.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pytest-logger-1.1.1.tar.gz
.
File metadata
- Download URL: pytest-logger-1.1.1.tar.gz
- Upload date:
- Size: 27.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 82cb36b505a72e15a2f0e12c6451d8c21ecbe0379d322b2bed4f05cb7842c9d9 |
|
MD5 | 02739b524a387f373c61e435ea059466 |
|
BLAKE2b-256 | 4b937df6dd24ce3e32666bfb45fd95dded221650a5ca5c13bc9d8bea47e13bab |
File details
Details for the file pytest_logger-1.1.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pytest_logger-1.1.1-py2.py3-none-any.whl
- Upload date:
- Size: 8.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9f7b88c04828de649a033779d30f359fce026fde37c1e91d83336a66d27a9fb |
|
MD5 | 580ab51ab19e90729ad9f3cfb380a46f |
|
BLAKE2b-256 | 76e48f8663e40fb225748944c685fd1ef0e3b9cfb88d6fc2749613f924e5c70e |