Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

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:
import os

def pytest_logger_config(logger_config):
    logger_config.add_loggers(['foo', 'bar', 'baz'], stdout_level='info')

def pytest_logger_logdirlink(config):
    return os.path.join(os.path.dirname(__file__), 'mylogs')

have logging tests or libraries (including fixtures):
import pytest
import logging

foo = logging.getLogger('foo')
bar = logging.getLogger('bar')
baz = logging.getLogger('baz')

def session_thing():
    foo.debug('constructing session thing')
    foo.debug('destroying session thing')

def testcase_thing():
    foo.debug('constructing testcase thing')
    foo.debug('destroying testcase thing')

def test_one(session_thing, testcase_thing):'one executes')
    bar.warning('this test does nothing aside from logging')'extra log, rarely read')

def test_two(session_thing, testcase_thing):'two executes')
    bar.warning('neither does this')'extra log, not enabled by default')

and expect output in terminal (if not captured):

$ py.test -s -v
00:00.002 inf foo: one executes
00:00.002 wrn bar: this test does nothing aside from logging
00:00.000 inf foo: two executes
00:00.000 wrn bar: neither does this

being able to change this output by cmdline option:

$ pytest -s -v --log foo.debug,baz
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
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

and - the same - in filesystem:

$ file mylogs
mylogs: symbolic link to `/tmp/pytest-of-aurzenligl/pytest-48/logs'

$ tree mylogs
    |-- 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.

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Hash SHA256 Hash Help Version File Type Upload Date
(10.4 kB) Copy SHA256 Hash SHA256
py2.py3 Wheel Nov 2, 2017
(24.8 kB) Copy SHA256 Hash SHA256
Source Nov 2, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting