Пример #1
0
    def test_repr_source_excinfo(self) -> None:
        """Check if indentation is right."""
        try:

            def f():
                1 / 0

            f()

        except BaseException:
            excinfo = _pytest._code.ExceptionInfo.from_current()
        else:
            assert False, "did not raise"

        pr = FormattedExcinfo()
        source = pr._getentrysource(excinfo.traceback[-1])
        assert source is not None
        lines = pr.get_source(source, 1, excinfo)
        for line in lines:
            print(line)
        assert lines == [
            "    def f():",
            ">       1 / 0",
            "E       ZeroDivisionError: division by zero",
        ]
Пример #2
0
 def test_repr_source_excinfo(self):
     """ check if indentation is right """
     pr = FormattedExcinfo()
     excinfo = self.excinfo_from_exec("""
             def f():
                 assert 0
             f()
     """)
     pr = FormattedExcinfo()
     source = pr._getentrysource(excinfo.traceback[-1])
     lines = pr.get_source(source, 1, excinfo)
     assert lines == [
         "    def f():", ">       assert 0", "E       AssertionError"
     ]
Пример #3
0
 def test_repr_source_excinfo(self):
     """ check if indentation is right """
     pr = FormattedExcinfo()
     excinfo = self.excinfo_from_exec(
         """
             def f():
                 assert 0
             f()
     """
     )
     pr = FormattedExcinfo()
     source = pr._getentrysource(excinfo.traceback[-1])
     lines = pr.get_source(source, 1, excinfo)
     assert lines == ["    def f():", ">       assert 0", "E       AssertionError"]