Skip to content

XML from --junit-xml filled in with log messages #2648

Closed
@AndreaCrotti

Description

@AndreaCrotti

Description

Using Pytest 3.2 and --junit-xml the output XML file gets polluted by logging messages.

Pip list

pytest==3.2.0
coverage==4.4.1
pytest-cov==2.5.1
pytest-reqs==0.0.6
mock==2.0.0

Versions

pytest==3.2.0 and nixos.

Example

This following example is enough to reproduce the issue.
If I run pytest tests.py the logging messages don't show (correctly).
Running instead pytest tests.py --junit-xml output.xml the log messages get into the XML file making it unusable.

import logging

logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)

logger = logging.getLogger(__name__)


def function():
    logger.info("Hello from inside a test")
    return 2


def test_sample():
    assert function() == 2


if __name__ == '__main__':
    function()

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: questiongeneral question, might be closed after 2 weeks of inactivity

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions