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

Function test_findsource

testing/code/test_source.py:326–344  ·  view source on GitHub ↗
(monkeypatch)

Source from the content-addressed store, hash-verified

324
325
326def test_findsource(monkeypatch) -> None:
327 from _pytest._code.source import findsource
328
329 filename = "<pytest-test_findsource>"
330 lines = ["if 1:\n", " def x():\n", " pass\n"]
331 co = compile("".join(lines), filename, "exec")
332
333 monkeypatch.setitem(linecache.cache, filename, (1, None, lines, filename))
334
335 src, lineno = findsource(co)
336 assert src is not None
337 assert "if 1:" in str(src)
338
339 d: dict[str, Any] = {}
340 eval(co, d)
341 src, lineno = findsource(d["x"])
342 assert src is not None
343 assert "if 1:" in str(src)
344 assert src[lineno] == " def x():"
345
346
347def test_getfslineno() -> None:

Callers

nothing calls this directly

Calls 3

findsourceFunction · 0.90
joinMethod · 0.80
setitemMethod · 0.80

Tested by

no test coverage detected