Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions subprojects/robotpy-wpilib/tests/test_pytest_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,26 @@ def test_robot_failure_output(robot):
assert robot_pid_one != robot_pid_two


def test_isolated_plugin_assertion_rendering(pytester):
_make_robot_module(pytester)
_configure_isolated_plugin(pytester)
pytester.makepyfile(test_isolated="""
def test_robot_assertion_rendering(robot):
assert "x" == "y"
""")

result = pytester.runpytest_subprocess("-vv")

result.assert_outcomes(failed=1)
result.stdout.fnmatch_lines(
[
"*test_isolated.py::test_robot_assertion_rendering FAILED*",
"*assert 'x' == 'y'*",
]
)
assert not any("_pytest/config/__init__.py" in line for line in result.outlines)


def test_isolated_plugin_no_duplicate_verbose_output(pytester):
_make_robot_module(pytester)
_configure_isolated_plugin(pytester)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@
from .pytest_plugin import RobotTestingPlugin


class _NullTerminalWriter:
def _highlight(self, source, lexer="python"):
return source


class _NullTerminalReporter:
"""Minimal terminal reporter used in worker processes."""

def __init__(self):
self._tw = _NullTerminalWriter()

def write(self, *args, **kwargs):
pass

def line(self, *args, **kwargs):
pass


def _enable_faulthandler():
#
# In the event of a segfault, faulthandler will dump the currently
Expand Down Expand Up @@ -66,6 +84,15 @@ def sendevent(self, name: str, **kwargs: object):
@pytest.hookimpl(wrapper=True)
def pytest_sessionstart(self, session: pytest.Session):
self.config = session.config

# When we disable terminalreporter in worker mode we still need a
# minimal reporter so assertion introspection can render diffs.
if self.config.pluginmanager.get_plugin("terminalreporter") is None:
self.config.pluginmanager.unblock("terminalreporter")
self.config.pluginmanager.register(
_NullTerminalReporter(), "terminalreporter"
)

return (yield)

@pytest.hookimpl
Expand Down
Loading