| 146 | |
| 147 | @classmethod |
| 148 | def _get_pdb_wrapper_class(cls, pdb_cls, capman: CaptureManager | None): |
| 149 | import _pytest.config |
| 150 | |
| 151 | class PytestPdbWrapper(pdb_cls): |
| 152 | _pytest_capman = capman |
| 153 | _continued = False |
| 154 | |
| 155 | def do_debug(self, arg): |
| 156 | cls._recursive_debug += 1 |
| 157 | ret = super().do_debug(arg) |
| 158 | cls._recursive_debug -= 1 |
| 159 | return ret |
| 160 | |
| 161 | if hasattr(pdb_cls, "do_debug"): |
| 162 | do_debug.__doc__ = pdb_cls.do_debug.__doc__ |
| 163 | |
| 164 | def do_continue(self, arg): |
| 165 | ret = super().do_continue(arg) |
| 166 | if cls._recursive_debug == 0: |
| 167 | assert cls._config is not None |
| 168 | tw = _pytest.config.create_terminal_writer(cls._config) |
| 169 | tw.line() |
| 170 | |
| 171 | capman = self._pytest_capman |
| 172 | capturing = pytestPDB._is_capturing(capman) |
| 173 | if capturing: |
| 174 | if capturing == "global": |
| 175 | tw.sep(">", "PDB continue (IO-capturing resumed)") |
| 176 | else: |
| 177 | tw.sep( |
| 178 | ">", |
| 179 | f"PDB continue (IO-capturing resumed for {capturing})", |
| 180 | ) |
| 181 | assert capman is not None |
| 182 | capman.resume() |
| 183 | else: |
| 184 | tw.sep(">", "PDB continue") |
| 185 | assert cls._pluginmanager is not None |
| 186 | cls._pluginmanager.hook.pytest_leave_pdb(config=cls._config, pdb=self) |
| 187 | self._continued = True |
| 188 | return ret |
| 189 | |
| 190 | if hasattr(pdb_cls, "do_continue"): |
| 191 | do_continue.__doc__ = pdb_cls.do_continue.__doc__ |
| 192 | |
| 193 | do_c = do_cont = do_continue |
| 194 | |
| 195 | def do_quit(self, arg): |
| 196 | # Raise Exit outcome when quit command is used in pdb. |
| 197 | # |
| 198 | # This is a bit of a hack - it would be better if BdbQuit |
| 199 | # could be handled, but this would require to wrap the |
| 200 | # whole pytest run, and adjust the report etc. |
| 201 | ret = super().do_quit(arg) |
| 202 | |
| 203 | if cls._recursive_debug == 0: |
| 204 | outcomes.exit("Quitting debugger") |
| 205 | |