Test behavior of Source with regard to decorators
Unlinke `inspect.getsource` it does not unwrap functions.
This commit is contained in:
parent
5a6296a2d7
commit
61180eec93
|
@ -624,6 +624,28 @@ def test_comment_in_statement() -> None:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_source_with_decorator() -> None:
|
||||||
|
"""Test behavior with Source / Code().source with regard to decorators."""
|
||||||
|
from _pytest.compat import get_real_func
|
||||||
|
|
||||||
|
@pytest.mark.foo
|
||||||
|
def deco_mark():
|
||||||
|
pass
|
||||||
|
|
||||||
|
src = inspect.getsource(deco_mark)
|
||||||
|
assert str(Source(deco_mark, deindent=False)) == src
|
||||||
|
assert src.startswith(" @pytest.mark.foo")
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def deco_fixture():
|
||||||
|
pass
|
||||||
|
|
||||||
|
src = inspect.getsource(deco_fixture)
|
||||||
|
assert src == " @pytest.fixture\n def deco_fixture():\n pass\n"
|
||||||
|
assert str(Source(deco_fixture)).startswith("@functools.wraps(function)")
|
||||||
|
assert str(Source(get_real_func(deco_fixture), deindent=False)) == src
|
||||||
|
|
||||||
|
|
||||||
def test_single_line_else() -> None:
|
def test_single_line_else() -> None:
|
||||||
source = getstatement(1, "if False: 2\nelse: 3")
|
source = getstatement(1, "if False: 2\nelse: 3")
|
||||||
assert str(source) == "else: 3"
|
assert str(source) == "else: 3"
|
||||||
|
|
Loading…
Reference in New Issue