Commit 096dca74 by Jeremy Bowman

Omit captured output in XML for passing tests

parent e26f0ed0
...@@ -12,6 +12,26 @@ import importlib ...@@ -12,6 +12,26 @@ import importlib
import os import os
import contracts import contracts
import pytest import pytest
from _pytest.junitxml import _NodeReporter, bin_xml_escape, Junit
def write_captured_output(self, report):
"""
Replacement for _NodeReporter.write_captured_output() in the junitxml
pytest plugin. Only outputs the captured stderr and stdout streams
for failing tests, which dramatically reduces the size of the
generated XML file.
A cleaner fix has been proposed at https://github.com/pytest-dev/pytest/issues/2889
"""
failed = any([node for node in self.nodes if node.__class__.__name__ != 'py._xmlgen.skipped'])
if not failed:
return
for capname in ('out', 'err'):
content = getattr(report, 'capstd' + capname)
if content:
tag = getattr(Junit, 'system-' + capname)
self.append(tag(bin_xml_escape(content)))
def pytest_configure(config): def pytest_configure(config):
...@@ -20,6 +40,7 @@ def pytest_configure(config): ...@@ -20,6 +40,7 @@ def pytest_configure(config):
""" """
if config.getoption('help'): if config.getoption('help'):
return return
_NodeReporter.write_captured_output = write_captured_output
enable_contracts = os.environ.get('ENABLE_CONTRACTS', False) enable_contracts = os.environ.get('ENABLE_CONTRACTS', False)
if not enable_contracts: if not enable_contracts:
contracts.disable_all() contracts.disable_all()
......
"""
common/lib unit test configuration.
"""
from django.conf import settings from django.conf import settings
from _pytest.junitxml import _NodeReporter, bin_xml_escape, Junit
def write_captured_output(self, report):
"""
Replacement for _NodeReporter.write_captured_output() in the junitxml
pytest plugin. Only outputs the captured stderr and stdout streams
for failing tests, which dramatically reduces the size of the
generated XML file.
A cleaner fix has been proposed at https://github.com/pytest-dev/pytest/issues/2889
"""
failed = any([node for node in self.nodes if node.__class__.__name__ != 'py._xmlgen.skipped'])
if not failed:
return
for capname in ('out', 'err'):
content = getattr(report, 'capstd' + capname)
if content:
tag = getattr(Junit, 'system-' + capname)
self.append(tag(bin_xml_escape(content)))
def pytest_configure(): def pytest_configure():
...@@ -6,3 +30,4 @@ def pytest_configure(): ...@@ -6,3 +30,4 @@ def pytest_configure():
Use Django's default settings for tests in common/lib. Use Django's default settings for tests in common/lib.
""" """
settings.configure() settings.configure()
_NodeReporter.write_captured_output = write_captured_output
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment