Test that exception in dynamically generated code doesn't break getting the source line.
(
pytester: Pytester, monkeypatch: MonkeyPatch
)
| 845 | |
| 846 | |
| 847 | def test_makereport_getsource_dynamic_code( |
| 848 | pytester: Pytester, monkeypatch: MonkeyPatch |
| 849 | ) -> None: |
| 850 | """Test that exception in dynamically generated code doesn't break getting the source line.""" |
| 851 | import inspect |
| 852 | |
| 853 | original_findsource = inspect.findsource |
| 854 | |
| 855 | def findsource(obj): |
| 856 | # Can be triggered by dynamically created functions |
| 857 | if obj.__name__ == "foo": |
| 858 | raise IndexError() |
| 859 | return original_findsource(obj) |
| 860 | |
| 861 | monkeypatch.setattr(inspect, "findsource", findsource) |
| 862 | |
| 863 | pytester.makepyfile( |
| 864 | """ |
| 865 | import pytest |
| 866 | |
| 867 | @pytest.fixture |
| 868 | def foo(missing): |
| 869 | pass |
| 870 | |
| 871 | def test_fix(foo): |
| 872 | assert False |
| 873 | """ |
| 874 | ) |
| 875 | result = pytester.runpytest("-vv") |
| 876 | result.stdout.no_fnmatch_line("*INTERNALERROR*") |
| 877 | result.stdout.fnmatch_lines(["*test_fix*", "*fixture*'missing'*not found*"]) |
| 878 | |
| 879 | |
| 880 | def test_store_except_info_on_error() -> None: |
nothing calls this directly
no test coverage detected