MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_line_with_reprcrash

Function test_line_with_reprcrash

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

Source from the content-addressed store, hash-verified

2253
2254
2255def test_line_with_reprcrash(monkeypatch: MonkeyPatch) -> None:
2256 mocked_verbose_word = "FAILED"
2257
2258 mocked_pos = "some::nodeid"
2259
2260 def mock_get_pos(*args):
2261 return mocked_pos
2262
2263 monkeypatch.setattr(_pytest.terminal, "_get_pos", mock_get_pos)
2264
2265 class config:
2266 pass
2267
2268 class rep:
2269 def _get_verbose_word(self, *args):
2270 return mocked_verbose_word
2271
2272 class longrepr:
2273 class reprcrash:
2274 pass
2275
2276 def check(msg, width, expected):
2277 __tracebackhide__ = True
2278 if msg:
2279 rep.longrepr.reprcrash.message = msg # type: ignore
2280 actual = _get_line_with_reprcrash_message(config, rep(), width) # type: ignore
2281
2282 assert actual == expected
2283 if actual != f"{mocked_verbose_word} {mocked_pos}":
2284 assert len(actual) <= width
2285 assert wcswidth(actual) <= width
2286
2287 # AttributeError with message
2288 check(None, 80, "FAILED some::nodeid")
2289
2290 check("msg", 80, "FAILED some::nodeid - msg")
2291 check("msg", 3, "FAILED some::nodeid")
2292
2293 check("msg", 24, "FAILED some::nodeid")
2294 check("msg", 25, "FAILED some::nodeid - msg")
2295
2296 check("some longer msg", 24, "FAILED some::nodeid")
2297 check("some longer msg", 25, "FAILED some::nodeid - ...")
2298 check("some longer msg", 26, "FAILED some::nodeid - s...")
2299
2300 check("some\nmessage", 25, "FAILED some::nodeid - ...")
2301 check("some\nmessage", 26, "FAILED some::nodeid - some")
2302 check("some\nmessage", 80, "FAILED some::nodeid - some")
2303
2304 # Test unicode safety.
2305 check("🉐🉐🉐🉐🉐\n2nd line", 25, "FAILED some::nodeid - ...")
2306 check("🉐🉐🉐🉐🉐\n2nd line", 26, "FAILED some::nodeid - ...")
2307 check("🉐🉐🉐🉐🉐\n2nd line", 27, "FAILED some::nodeid - 🉐...")
2308 check("🉐🉐🉐🉐🉐\n2nd line", 28, "FAILED some::nodeid - 🉐...")
2309 check("🉐🉐🉐🉐🉐\n2nd line", 29, "FAILED some::nodeid - 🉐🉐...")
2310
2311 # NOTE: constructed, not sure if this is supported.
2312 mocked_pos = "nodeid::🉐::withunicode"

Callers

nothing calls this directly

Calls 2

setattrMethod · 0.80
checkFunction · 0.70

Tested by

no test coverage detected