src/_pytest/_code/code.py
<<<<<<< SEARCH
        reprtraceback: "ReprTraceback",
        reprcrash: Optional["ReprFileLocation"],
        sections: Iterable[Tuple[str, str, str]] = (),
    ) -> None:
        super().__init__(sections)
        self.reprtraceback = reprtraceback
        self.reprcrash = reprcrash
=======
        reprtraceback: "ReprTraceback",
        reprcrash: Optional["ReprFileLocation"],
        sections: Iterable[Tuple[str, str, str]] = (),
        chain: Iterable[
            Tuple["ReprTraceback", Optional["ReprFileLocation"], Optional[str]]
        ] = (),
    ) -> None:
        super().__init__(sections)
        self.reprtraceback = reprtraceback
        self.reprcrash = reprcrash
        self.chain = list(chain)
>>>>>>> REPLACE
src/_pytest/_code/code.py
<<<<<<< SEARCH
    def toterminal(self, tw: TerminalWriter) -> None:
        self.reprtraceback.toterminal(tw)
=======
    def toterminal(self, tw: TerminalWriter) -> None:
        if getattr(self, "chain", None):
            for _traceback, _crash, _description in self.chain:
                if _description is not None:
                    tw.line()
                    tw.line(_description, yellow=True)
                    tw.line()
                _traceback.toterminal(tw)
                if _crash is not None:
                    _crash.toterminal(tw)
            super().toterminal(tw)
            return
        self.reprtraceback.toterminal(tw)
>>>>>>> REPLACE
src/_pytest/_code/code.py
<<<<<<< SEARCH
    def getrepr(
        self,
        showlocals: bool = False,
        style: str = "long",
        abspath: bool = False,
        tbfilter: bool = True,
        funcargs: bool = False,
        truncate_locals: bool = True,
        truncate_args: bool = True,
    ) -> Union["ReprExceptionInfo", "TerminalRepr"]:
=======
    def getrepr(
        self,
        showlocals: bool = False,
        style: str = "long",
        abspath: bool = False,
        tbfilter: bool = True,
        funcargs: bool = False,
        truncate_locals: bool = True,
        truncate_args: bool = True,
        chain: bool = True,
    ) -> Union["ReprExceptionInfo", "TerminalRepr"]:
>>>>>>> REPLACE
src/_pytest/_code/code.py
<<<<<<< SEARCH
        if style == "native":
=======
        if chain and style in ("long", "short"):
            _infos = []
            _cur = self
            _seen = set()
            while _cur is not None and id(_cur.value) not in _seen:
                _seen.add(id(_cur.value))
                _infos.append(_cur)
                _cause = getattr(_cur.value, "__cause__", None)
                _context = getattr(_cur.value, "__context__", None)
                if _cause is not None:
                    _nxt = _cause
                elif _context is not None and not getattr(
                    _cur.value, "__suppress_context__", False
                ):
                    _nxt = _context
                else:
                    break
                try:
                    _cur = ExceptionInfo.from_exc_info(
                        (type(_nxt), _nxt, _nxt.__traceback__)
                    )
                except AttributeError:
                    _cur = ExceptionInfo(  # type: ignore[call-arg]
                        (type(_nxt), _nxt, _nxt.__traceback__)
                    )
            if len(_infos) > 1:
                _infos.reverse()
                _chain = []
                for _i, _info in enumerate(_infos):
                    _repr = _info.getrepr(
                        showlocals=showlocals,
                        style=style,
                        abspath=abspath,
                        tbfilter=tbfilter,
                        funcargs=funcargs,
                        truncate_locals=truncate_locals,
                        truncate_args=truncate_args,
                        chain=False,
                    )
                    if _i == 0:
                        _descr = None
                    elif getattr(_info.value, "__cause__", None) is _infos[_i - 1].value:
                        _descr = "The above exception was the direct cause of the following exception:"
                    else:
                        _descr = "During handling of the above exception, another exception occurred:"
                    _chain.append((_repr.reprtraceback, _repr.reprcrash, _descr))  # type: ignore[attr-defined]
                return ReprExceptionInfo(_chain[-1][0], _chain[-1][1], chain=_chain)
        if style == "native":
>>>>>>> REPLACE