Commits

Ronny Pfannschmidt committed 2ffc28a

ensure tracebackitem.source returns the actual line if it cant find a statement range

  • Participants
  • Parent commits be8202d

Comments (0)

Files changed (2)

         end = self.lineno
         try:
             _, end = source.getstatementrange(end)
-        except IndexError:
+        except (IndexError, ValueError):
             end = self.lineno + 1
-        except ValueError:
-            pass
         # heuristic to stop displaying source on e.g.
         #   if something:  # assume this causes a NameError
         #      # _this_ lines and the one

testing/code/test_excinfo.py

     for item in excinfo.traceback:
         print(item) #XXX: for some reason jinja.Template.render is printed in full
         item.source # shouldnt fail
+        if item.path.basename == 'test.txt':
+            assert str(item.source) == '{{ h()}}:'
 
 
 def test_entrysource_Queue_example():