Skip to main content

Plugin configuring handlers for loggers from Python logging module.

Project description

Pypi Package Version Supported Python Versions Documentation Status Coverage Status Travis-CI Build Status AppVeyor-CI Build Status

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 hooks:

#conftest.py
import os

def pytest_logger_stdoutloggers(item):
    return ['foo', 'bar']

def pytest_logger_fileloggers(item):
    return ['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')
foo.setLevel(logging.INFO)

bar = logging.getLogger('bar')

@pytest.yield_fixture(scope='session')
def session_thing():
    foo.info('constructing session thing')
    yield
    foo.info('destroying session thing')

@pytest.yield_fixture
def testcase_thing():
    foo.info('constructing testcase thing')
    yield
    foo.info('destroying testcase thing')

def test_one(session_thing, testcase_thing):
    foo.info('one executes')
    bar.warning('this test does nothing aside from logging')

def test_two(session_thing, testcase_thing):
    foo.info('two executes')
    bar.warning('neither does this')

and expect output in terminal (if not captured):

$ py.test -s -v
(...)
test_something.py::test_one
00:00.001 inf foo: constructing session thing
00:00.001 inf foo: constructing testcase thing
00:00.002 inf foo: one executes
00:00.002 wrn bar: this test does nothing aside from logging
PASSED
00:00.002 inf foo: destroying testcase thing

test_something.py::test_two
00:00.000 inf foo: constructing testcase thing
00:00.000 inf foo: two executes
00:00.000 wrn bar: neither does this
PASSED
00:00.001 inf foo: destroying testcase thing
00:00.001 inf foo: destroying session thing
(...)

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
    |   `-- foo
    `-- test_two
        |-- bar
        `-- foo

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

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-logger-0.1.3.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

pytest_logger-0.1.3-py2.py3-none-any.whl (8.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pytest-logger-0.1.3.tar.gz.

File metadata

  • Download URL: pytest-logger-0.1.3.tar.gz
  • Upload date:
  • Size: 19.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pytest-logger-0.1.3.tar.gz
Algorithm Hash digest
SHA256 e869eb19159113a83f26fb4cc76c10092a8801fbbb5ea8805f748af5d79b8e1e
MD5 3d82f2126276bd0a8eea78d31ae75f36
BLAKE2b-256 1dd4b73829344be7659f29ce4752e2baa766ad79fa5c61dd7fe5e3bacdc781bb

See more details on using hashes here.

File details

Details for the file pytest_logger-0.1.3-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pytest_logger-0.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5cfd8d90a76fe6cc5f26d62705d4211774b9cd21024950e03389379dc6363737
MD5 1bb75658b170e6b87e22425dd6ef788b
BLAKE2b-256 82753660c50f8ca273ab2979f865141dbdebb3c5265aad30b6f4700622414e4a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page