Skip to content
This repository was archived by the owner on Jun 1, 2026. It is now read-only.

Commit 642865b

Browse files
authored
Merge pull request #255 from robotpy/fix-assertion-rendering
Fix isolated pytest assertion rendering in worker process
2 parents e7a9388 + 1567b2c commit 642865b

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

pyfrc/test_support/pytest_isolated_tests_plugin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@
1919
from .pytest_plugin import PyFrcPlugin
2020

2121

22+
class _NullTerminalWriter:
23+
def _highlight(self, source, lexer="python"):
24+
return source
25+
26+
27+
class _NullTerminalReporter:
28+
"""Minimal terminal reporter used in worker processes."""
29+
30+
def __init__(self):
31+
self._tw = _NullTerminalWriter()
32+
33+
def write(self, *args, **kwargs):
34+
pass
35+
36+
def line(self, *args, **kwargs):
37+
pass
38+
39+
2240
def _enable_faulthandler():
2341
#
2442
# In the event of a segfault, faulthandler will dump the currently
@@ -67,6 +85,15 @@ def sendevent(self, name: str, **kwargs: object):
6785
@pytest.hookimpl(wrapper=True)
6886
def pytest_sessionstart(self, session: pytest.Session):
6987
self.config = session.config
88+
89+
# When we disable terminalreporter in worker mode we still need a
90+
# minimal reporter so assertion introspection can render diffs.
91+
if self.config.pluginmanager.get_plugin("terminalreporter") is None:
92+
self.config.pluginmanager.unblock("terminalreporter")
93+
self.config.pluginmanager.register(
94+
_NullTerminalReporter(), "terminalreporter"
95+
)
96+
7097
return (yield)
7198

7299
@pytest.hookimpl

tests/test_pytest_plugins.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ def test_robot_failure_output(robot):
177177
assert robot_pid_one != robot_pid_two
178178

179179

180+
def test_isolated_plugin_assertion_rendering(pytester):
181+
_make_robot_module(pytester)
182+
_configure_isolated_plugin(pytester)
183+
pytester.makepyfile(test_isolated="""
184+
def test_robot_assertion_rendering(robot):
185+
assert "x" == "y"
186+
""")
187+
188+
result = pytester.runpytest_subprocess("-vv")
189+
190+
result.assert_outcomes(failed=1)
191+
result.stdout.fnmatch_lines(
192+
[
193+
"*test_isolated.py::test_robot_assertion_rendering FAILED*",
194+
"*assert 'x' == 'y'*",
195+
]
196+
)
197+
assert not any("_pytest/config/__init__.py" in line for line in result.outlines)
198+
199+
180200
def test_isolated_plugin_no_duplicate_verbose_output(pytester):
181201
_make_robot_module(pytester)
182202
_configure_isolated_plugin(pytester)

0 commit comments

Comments
 (0)