Closed
Description
Logs for failed test are passed to junit report only in case the test fails during teardown phase.
Seems as regression related to the change #5052.
$ pip list
Package Version
------------------ -------
atomicwrites 1.3.0
attrs 19.1.0
importlib-metadata 0.17
more-itertools 7.0.0
packaging 19.0
pathlib2 2.3.3
pip 19.1.1
pluggy 0.12.0
py 1.8.0
pyparsing 2.4.0
pytest 4.6.2
setuptools 41.0.1
six 1.12.0
wcwidth 0.1.7
wheel 0.33.4
zipp 0.5.1
Example test_me.py
:
import pytest
import logging
logger = logging.getLogger(__name__)
def test_passed():
logging.info('logs from passed test')
assert True
def test_failed():
logging.info('no logs from test failed not in a teardown phase')
assert False
@pytest.fixture
def faulty_fixture():
yield
assert False
def test_failed_during_teardown(faulty_fixture):
logging.info('logs from test failed during teardown')
assert True
The command: python -m pytest -l -v test_me.py --junit-xml=report.xml --log-level info
produces the following junit report:
<?xml version="1.0" encoding="utf-8"?><testsuite errors="1" failures="1" name="pytest" skipped="0" tests="4" time="0.031"><testcase classname="test_me" file="test_me.py" line="6" name="test_passed" time="0.001"></testcase><testcase classname="test_me" file="test_me.py" line="11" name="test_failed" time="0.001"><failure message="assert False">def test_failed():
logging.info('no logs from test failed not in a teardown phase')
> assert False
E assert False
test_me.py:14: AssertionError</failure></testcase><testcase classname="test_me" file="test_me.py" line="22" name="test_failed_during_teardown" time="0.001"><error message="test teardown failure">@pytest.fixture
def faulty_fixture():
yield
> assert False
E assert False
test_me.py:20: AssertionError</error><system-err>#x1B[32mINFO #x1B[0m root:test_me.py:24 logs from test failed during teardown</system-err></testcase></testsuite>