MCPcopy Index your code
hub / github.com/pytest-dev/pytest / test_source_with_decorator

Function test_source_with_decorator

testing/code/test_source.py:467–490  ·  view source on GitHub ↗

Test behavior with Source / Code().source with regard to decorators.

()

Source from the content-addressed store, hash-verified

465
466
467def test_source_with_decorator() -> None:
468 """Test behavior with Source / Code().source with regard to decorators."""
469
470 @pytest.mark.foo
471 def deco_mark():
472 assert False
473
474 src = inspect.getsource(deco_mark)
475 assert textwrap.indent(str(Source(deco_mark)), " ") + "\n" == src
476 assert src.startswith(" @pytest.mark.foo")
477
478 @pytest.fixture
479 def deco_fixture():
480 assert False
481
482 src = inspect.getsource(deco_fixture._get_wrapped_function())
483 assert src == " @pytest.fixture\n def deco_fixture():\n assert False\n"
484 # Make sure the decorator is not a wrapped function
485 assert not str(Source(deco_fixture)).startswith("@functools.wraps(function)")
486 assert (
487 textwrap.indent(str(Source(deco_fixture._get_wrapped_function())), " ")
488 + "\n"
489 == src
490 )
491
492
493def test_single_line_else() -> None:

Callers

nothing calls this directly

Calls 4

SourceClass · 0.90
getsourceMethod · 0.80
indentMethod · 0.80
_get_wrapped_functionMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…