Fix issue 1947

This was harder than I initially thought but it should be fixed now.

Instead of pasting the _find_lineno function from the stdlib into the
SymPyDocTestFinder class,  I tried to fix the parts which required a modification
of _find_lineno directly in the _find function.