def test_makereport_getsource_dynamic_code(testdir, monkeypatch):
 import inspect
 original_findsource = inspect.findsource
 def findsource(obj, *args, **kwargs):
  if (obj.__name__ == 'foo'):
   raise IndexError()
  return original_findsource(obj, *args, **kwargs)
 monkeypatch.setattr(inspect, 'findsource', findsource)
 testdir.makepyfile('\n        import pytest\n\n        @pytest.fixture\n        def foo(missing):\n            pass\n\n        def test_fix(foo):\n            assert False\n    ')
 result = testdir.runpytest('-vv')
 assert ('INTERNALERROR' not in result.stdout.str())
 result.stdout.fnmatch_lines(['*test_fix*', "*fixture*'missing'*not found*"])

def test_makereport_getsource_dynamic_code ( testdir , monkeypatch ) : import inspect original_findsource = inspect . findsource def findsource ( obj , * args , ** kwargs ) : if ( obj . __name__ == 'foo' ) : raise IndexError ( ) return original_findsource ( obj , * args , ** kwargs ) monkeypatch . setattr ( inspect , 'findsource' , findsource ) testdir . makepyfile ( '\n        import pytest\n\n        @pytest.fixture\n        def foo(missing):\n            pass\n\n        def test_fix(foo):\n            assert False\n    ' ) result = testdir . runpytest ( '-vv' ) assert ( 'INTERNALERROR' not in result . stdout . str ( ) ) result . stdout . fnmatch_lines ( [ '*test_fix*' , "*fixture*'missing'*not found*" ] )
test that exception in dynamically generated code doesnt break getting the source line .