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

Function test_source_with_decorator

testing/code/test_source.py:469–493  ·  view source on GitHub ↗

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

()

Source from the content-addressed store, hash-verified

467
468
469def test_source_with_decorator() -> None:
470 """Test behavior with Source / Code().source with regard to decorators."""
471 from _pytest.compat import get_real_func
472
473 @pytest.mark.foo
474 def deco_mark():
475 assert False
476
477 src = inspect.getsource(deco_mark)
478 assert textwrap.indent(str(Source(deco_mark)), " ") + "\n" == src
479 assert src.startswith(" @pytest.mark.foo")
480
481 @pytest.fixture
482 def deco_fixture():
483 assert False
484
485 src = inspect.getsource(deco_fixture)
486 assert src == " @pytest.fixture\n def deco_fixture():\n assert False\n"
487 # currently Source does not unwrap decorators, testing the
488 # existing behavior here for explicitness, but perhaps we should revisit/change this
489 # in the future
490 assert str(Source(deco_fixture)).startswith("@functools.wraps(function)")
491 assert (
492 textwrap.indent(str(Source(get_real_func(deco_fixture))), " ") + "\n" == src
493 )
494
495
496def test_single_line_else() -> None:

Callers

nothing calls this directly

Calls 4

SourceClass · 0.90
get_real_funcFunction · 0.90
getsourceMethod · 0.80
indentMethod · 0.80

Tested by

no test coverage detected