#4445: Make sure the warning points to a reasonable location See origin of _issue_warning_captured at: _pytest.assertion.rewrite.py:241
(self, pytester: Pytester, capwarn)
| 670 | return CapturedWarnings |
| 671 | |
| 672 | def test_issue4445_rewrite(self, pytester: Pytester, capwarn) -> None: |
| 673 | """#4445: Make sure the warning points to a reasonable location |
| 674 | See origin of _issue_warning_captured at: _pytest.assertion.rewrite.py:241 |
| 675 | """ |
| 676 | pytester.makepyfile(some_mod="") |
| 677 | conftest = pytester.makeconftest( |
| 678 | """ |
| 679 | import some_mod |
| 680 | import pytest |
| 681 | |
| 682 | pytest.register_assert_rewrite("some_mod") |
| 683 | """ |
| 684 | ) |
| 685 | pytester.parseconfig() |
| 686 | |
| 687 | # with stacklevel=5 the warning originates from register_assert_rewrite |
| 688 | # function in the created conftest.py |
| 689 | assert len(capwarn.captured) == 1 |
| 690 | warning, location = capwarn.captured.pop() |
| 691 | file, lineno, func = location |
| 692 | |
| 693 | assert "Module already imported" in str(warning.message) |
| 694 | assert file == str(conftest) |
| 695 | assert func == "<module>" # the above conftest.py |
| 696 | assert lineno == 4 |
| 697 | |
| 698 | def test_issue4445_preparse(self, pytester: Pytester, capwarn) -> None: |
| 699 | """#4445: Make sure the warning points to a reasonable location |
nothing calls this directly
no test coverage detected