There is a flaky test, and we have no clue what the root cause could be. with pytest.raises(foo.geocoder.GeocodingFailed): foo.geocoder.geocode('not a valid place') Sometimes the exception does not happen. I looked at the docs how to handle failures, but this did not help. How to trace geocode() so that if the exception does not happen, I see a trace? I looked at the trace module of the standard library. But there seems to be no easy way to get the trace as string. With "a trace" I mean: A trace of all lines which got executed during gecode(). I would like to see method calls and returns statements with indentation. I want to ignore lines from the Python standard library. AFAIK a debugger like pdb does not help here, since the test only fails when it gets run in CI, and only once or twice per month. Continue reading...