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

Function test_getfslineno

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

Source from the content-addressed store, hash-verified

345
346
347def test_getfslineno() -> None:
348 def f(x) -> None:
349 raise NotImplementedError()
350
351 fspath, lineno = getfslineno(f)
352
353 assert isinstance(fspath, Path)
354 assert fspath.name == "test_source.py"
355 assert lineno == f.__code__.co_firstlineno - 1 # see findsource
356
357 class A:
358 pass
359
360 fspath, lineno = getfslineno(A)
361
362 _, A_lineno = inspect.findsource(A)
363 assert isinstance(fspath, Path)
364 assert fspath.name == "test_source.py"
365 assert lineno == A_lineno
366
367 assert getfslineno(3) == ("", -1)
368
369 class B:
370 pass
371
372 B.__name__ = B.__qualname__ = "B2"
373 # Since Python 3.13 this started working.
374 if sys.version_info >= (3, 13):
375 assert getfslineno(B)[1] != -1
376 else:
377 assert getfslineno(B)[1] == -1
378
379
380def test_code_of_object_instance_with_call() -> None:

Callers

nothing calls this directly

Calls 1

getfslinenoFunction · 0.90

Tested by

no test coverage detected