pytest-logger


Namepytest-logger JSON
Version 1.1.1 PyPI version JSON
download
home_pagehttps://github.com/aurzenligl/pytest-logger
SummaryPlugin configuring handlers for loggers from Python logging module.
upload_time2024-03-10 19:19:12
maintainerKrzysztof Laskowski
docs_urlNone
authorKrzysztof Laskowski
requires_python
licenseMIT
keywords py.test pytest logging
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            .. image:: https://img.shields.io/pypi/v/pytest-logger.svg
    :target: https://pypi.python.org/pypi/pytest-logger
    :alt: Pypi Package Version
.. image:: https://img.shields.io/pypi/pyversions/pytest-logger.svg
    :target: https://pypi.python.org/pypi/pytest-logger
    :alt: Supported Python Versions
.. image:: https://readthedocs.org/projects/pytest-logger/badge
    :target: http://pytest-logger.readthedocs.io/en/latest
    :alt: Documentation Status
.. image:: https://coveralls.io/repos/github/aurzenligl/pytest-logger/badge.svg?branch=master
    :target: https://coveralls.io/github/aurzenligl/pytest-logger?branch=master
    :alt: Coverage Status
.. image:: https://github.com/aurzenligl/pytest-logger/workflows/test/badge.svg
    :target: https://github.com/aurzenligl/pytest-logger/actions?query=workflow%3Atest
.. image:: https://ci.appveyor.com/api/projects/status/1h4cy8tk220pn03o?svg=true
    :target: https://ci.appveyor.com/project/aurzenligl/pytest-logger
    :alt: 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 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.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/aurzenligl/pytest-logger",
    "name": "pytest-logger",
    "maintainer": "Krzysztof Laskowski",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "aurzenligl@gmail.com",
    "keywords": "py.test pytest logging",
    "author": "Krzysztof Laskowski",
    "author_email": "aurzenligl@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4b/93/7df6dd24ce3e32666bfb45fd95dded221650a5ca5c13bc9d8bea47e13bab/pytest-logger-1.1.1.tar.gz",
    "platform": null,
    "description": ".. image:: https://img.shields.io/pypi/v/pytest-logger.svg\n    :target: https://pypi.python.org/pypi/pytest-logger\n    :alt: Pypi Package Version\n.. image:: https://img.shields.io/pypi/pyversions/pytest-logger.svg\n    :target: https://pypi.python.org/pypi/pytest-logger\n    :alt: Supported Python Versions\n.. image:: https://readthedocs.org/projects/pytest-logger/badge\n    :target: http://pytest-logger.readthedocs.io/en/latest\n    :alt: Documentation Status\n.. image:: https://coveralls.io/repos/github/aurzenligl/pytest-logger/badge.svg?branch=master\n    :target: https://coveralls.io/github/aurzenligl/pytest-logger?branch=master\n    :alt: Coverage Status\n.. image:: https://github.com/aurzenligl/pytest-logger/workflows/test/badge.svg\n    :target: https://github.com/aurzenligl/pytest-logger/actions?query=workflow%3Atest\n.. image:: https://ci.appveyor.com/api/projects/status/1h4cy8tk220pn03o?svg=true\n    :target: https://ci.appveyor.com/project/aurzenligl/pytest-logger\n    :alt: AppVeyor-CI Build Status\n\nPytest-logger is a pytest plugin configuring handlers for loggers from Python logging module.\n\nYou can install pytest-logger via ``pip`` from ``PyPI``::\n\n    $ [sudo] pip install pytest-logger\n\nPlugin puts logs on per-logger basis to:\n\n- standard output,\n- files within log-specific directory under pytest's ``tmpdir_factory`` session directory.\n\nYou can setup plugin using hook::\n\n    #conftest.py\n    import os\n\n    def pytest_logger_config(logger_config):\n        logger_config.add_loggers(['foo', 'bar', 'baz'], stdout_level='info')\n        logger_config.set_log_option_default('foo,bar')\n\n    def pytest_logger_logdirlink(config):\n        return os.path.join(os.path.dirname(__file__), 'mylogs')\n\nhave logging tests or libraries (including fixtures)::\n\n    #test_something.py\n    import pytest\n    import logging\n\n    foo = logging.getLogger('foo')\n    bar = logging.getLogger('bar')\n    baz = logging.getLogger('baz')\n\n    @pytest.yield_fixture(scope='session')\n    def session_thing():\n        foo.debug('constructing session thing')\n        yield\n        foo.debug('destroying session thing')\n\n    @pytest.yield_fixture\n    def testcase_thing():\n        foo.debug('constructing testcase thing')\n        yield\n        foo.debug('destroying testcase thing')\n\n    def test_one(session_thing, testcase_thing):\n        foo.info('one executes')\n        bar.warning('this test does nothing aside from logging')\n        baz.info('extra log, rarely read')\n\n    def test_two(session_thing, testcase_thing):\n        foo.info('two executes')\n        bar.warning('neither does this')\n        baz.info('extra log, not enabled by default')\n\nand expect output in terminal (if not captured)::\n\n    $ py.test -s -v\n    (...)\n    test_something.py::test_one\n    00:00.002 inf foo: one executes\n    00:00.002 wrn bar: this test does nothing aside from logging\n    PASSED\n\n    test_something.py::test_two\n    00:00.000 inf foo: two executes\n    00:00.000 wrn bar: neither does this\n    PASSED\n\nbeing able to change this output by cmdline option::\n\n    $ pytest -s -v --log foo.debug,baz\n    (...)\n    test_something.py::test_one\n    00:00.002 dbg foo: constructing session thing\n    00:00.002 dbg foo: constructing testcase thing\n    00:00.002 inf foo: one executes\n    00:00.003 inf baz: extra log, rarely read\n    PASSED\n\n    test_something.py::test_two\n    00:00.000 dbg foo: constructing testcase thing\n    00:00.000 inf foo: two executes\n    00:00.001 inf baz: extra log, not enabled by default\n    PASSED\n\nand - the same - in filesystem::\n\n    $ file mylogs\n    mylogs: symbolic link to `/tmp/pytest-of-aurzenligl/pytest-48/logs'\n\n    $ tree mylogs\n    mylogs\n    `-- test_something.py\n        |-- test_one\n        |   |-- bar\n        |   |-- baz\n        |   `-- foo\n        `-- test_two\n            |-- bar\n            |-- baz\n            `-- foo\n\nDistributed under the terms of the ``MIT`` license, pytest-logger is free and open source software.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Plugin configuring handlers for loggers from Python logging module.",
    "version": "1.1.1",
    "project_urls": {
        "Homepage": "https://github.com/aurzenligl/pytest-logger"
    },
    "split_keywords": [
        "py.test",
        "pytest",
        "logging"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "76e48f8663e40fb225748944c685fd1ef0e3b9cfb88d6fc2749613f924e5c70e",
                "md5": "580ab51ab19e90729ad9f3cfb380a46f",
                "sha256": "d9f7b88c04828de649a033779d30f359fce026fde37c1e91d83336a66d27a9fb"
            },
            "downloads": -1,
            "filename": "pytest_logger-1.1.1-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "580ab51ab19e90729ad9f3cfb380a46f",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 8896,
            "upload_time": "2024-03-10T19:19:11",
            "upload_time_iso_8601": "2024-03-10T19:19:11.666633Z",
            "url": "https://files.pythonhosted.org/packages/76/e4/8f8663e40fb225748944c685fd1ef0e3b9cfb88d6fc2749613f924e5c70e/pytest_logger-1.1.1-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b937df6dd24ce3e32666bfb45fd95dded221650a5ca5c13bc9d8bea47e13bab",
                "md5": "02739b524a387f373c61e435ea059466",
                "sha256": "82cb36b505a72e15a2f0e12c6451d8c21ecbe0379d322b2bed4f05cb7842c9d9"
            },
            "downloads": -1,
            "filename": "pytest-logger-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "02739b524a387f373c61e435ea059466",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 27720,
            "upload_time": "2024-03-10T19:19:12",
            "upload_time_iso_8601": "2024-03-10T19:19:12.989700Z",
            "url": "https://files.pythonhosted.org/packages/4b/93/7df6dd24ce3e32666bfb45fd95dded221650a5ca5c13bc9d8bea47e13bab/pytest-logger-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-10 19:19:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "aurzenligl",
    "github_project": "pytest-logger",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "appveyor": true,
    "tox": true,
    "lcname": "pytest-logger"
}
        
Elapsed time: 0.19182s