MCPcopy Create free account
hub / github.com/pytest-dev/pytest / test_makereport_getsource_dynamic_code

Function test_makereport_getsource_dynamic_code

testing/test_runner.py:847–877  ·  view source on GitHub ↗

Test that exception in dynamically generated code doesn't break getting the source line.

(
    pytester: Pytester, monkeypatch: MonkeyPatch
)

Source from the content-addressed store, hash-verified

845
846
847def 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
880def test_store_except_info_on_error() -> None:

Callers

nothing calls this directly

Calls 5

setattrMethod · 0.80
no_fnmatch_lineMethod · 0.80
fnmatch_linesMethod · 0.80
makepyfileMethod · 0.45
runpytestMethod · 0.45

Tested by

no test coverage detected