MCPcopy
hub / github.com/pytest-dev/pytest / test_line_with_reprcrash

Function test_line_with_reprcrash

testing/test_terminal.py:2554–2632  ·  view source on GitHub ↗
(monkeypatch: MonkeyPatch)

Source from the content-addressed store, hash-verified

2552
2553
2554def test_line_with_reprcrash(monkeypatch: MonkeyPatch) -> None:
2555 mocked_verbose_word = "FAILED"
2556
2557 mocked_pos = "some::nodeid"
2558
2559 def mock_get_pos(*args):
2560 return mocked_pos
2561
2562 monkeypatch.setattr(_pytest.terminal, "_get_node_id_with_markup", mock_get_pos)
2563
2564 class Namespace:
2565 def __init__(self, **kwargs):
2566 self.__dict__.update(kwargs)
2567
2568 class config:
2569 def __init__(self):
2570 self.option = Namespace(verbose=0)
2571
2572 class rep:
2573 def _get_verbose_word_with_markup(self, *args):
2574 return mocked_verbose_word, {}
2575
2576 class longrepr:
2577 class reprcrash:
2578 pass
2579
2580 def check(msg, width, expected):
2581 class DummyTerminalWriter:
2582 fullwidth = width
2583
2584 def markup(self, word: str, **markup: str):
2585 return word
2586
2587 __tracebackhide__ = True
2588 if msg:
2589 rep.longrepr.reprcrash.message = msg # type: ignore
2590 actual = _get_line_with_reprcrash_message(
2591 config(), # type: ignore[arg-type]
2592 rep(), # type: ignore[arg-type]
2593 DummyTerminalWriter(), # type: ignore[arg-type]
2594 {},
2595 )
2596
2597 assert actual == expected
2598 if actual != f"{mocked_verbose_word} {mocked_pos}":
2599 assert len(actual) <= width
2600 assert wcswidth(actual) <= width
2601
2602 # AttributeError with message
2603 check(None, 80, "FAILED some::nodeid")
2604
2605 check("msg", 80, "FAILED some::nodeid - msg")
2606 check("msg", 3, "FAILED some::nodeid")
2607
2608 check("msg", 24, "FAILED some::nodeid")
2609 check("msg", 25, "FAILED some::nodeid - msg")
2610
2611 check("some longer msg", 24, "FAILED some::nodeid")

Callers

nothing calls this directly

Calls 2

setattrMethod · 0.80
checkFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…