(monkeypatch)
| 324 | |
| 325 | |
| 326 | def 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 | |
| 347 | def test_getfslineno() -> None: |
nothing calls this directly
no test coverage detected