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

Function test_findsource

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

findsourceFunction · 0.90
setitemMethod · 0.80

Tested by

no test coverage detected