Test behavior with Source / Code().source with regard to decorators.
()
| 465 | |
| 466 | |
| 467 | def 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 | |
| 493 | def test_single_line_else() -> None: |
nothing calls this directly
no test coverage detected
searching dependent graphs…