Test behavior with Source / Code().source with regard to decorators.
()
| 467 | |
| 468 | |
| 469 | def 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 | |
| 496 | def test_single_line_else() -> None: |
nothing calls this directly
no test coverage detected