def test_source_with_decorator() -> None:
    """Test behavior with Source / Code().source with regard to decorators."""

    @pytest.mark.foo
    def deco_mark():
        assert False

    src = inspect.getsource(deco_mark)
    assert textwrap.indent(str(Source(deco_mark)), "    ") + "\n" == src
    assert src.startswith("    @pytest.mark.foo")

    @pytest.fixture
    def deco_fixture():
        assert False

    src = inspect.getsource(deco_fixture._get_wrapped_function())
    assert src == "    @pytest.fixture\n    def deco_fixture():\n        assert False\n"
    # Make sure the decorator is not a wrapped function
    assert not str(Source(deco_fixture)).startswith("@functools.wraps(function)")
    assert (
        textwrap.indent(str(Source(deco_fixture._get_wrapped_function())), "    ")
        + "\n"
        == src
    )
Test behavior with Source / Code().source with regard to decorators.
testing/code/test_source.py