Simulates pdbpp, which injects Pdb into do_debug, and uses self.__class__ in do_continue.
(self, pytester: Pytester)
| 565 | self.flush(child) |
| 566 | |
| 567 | def test_pdb_with_injected_do_debug(self, pytester: Pytester) -> None: |
| 568 | """Simulates pdbpp, which injects Pdb into do_debug, and uses |
| 569 | self.__class__ in do_continue. |
| 570 | """ |
| 571 | p1 = pytester.makepyfile( |
| 572 | mytest=""" |
| 573 | import pdb |
| 574 | import pytest |
| 575 | |
| 576 | count_continue = 0 |
| 577 | |
| 578 | class CustomPdb(pdb.Pdb, object): |
| 579 | def do_debug(self, arg): |
| 580 | import sys |
| 581 | import types |
| 582 | |
| 583 | do_debug_func = pdb.Pdb.do_debug |
| 584 | |
| 585 | newglobals = do_debug_func.__globals__.copy() |
| 586 | newglobals['Pdb'] = self.__class__ |
| 587 | orig_do_debug = types.FunctionType( |
| 588 | do_debug_func.__code__, newglobals, |
| 589 | do_debug_func.__name__, do_debug_func.__defaults__, |
| 590 | ) |
| 591 | return orig_do_debug(self, arg) |
| 592 | do_debug.__doc__ = pdb.Pdb.do_debug.__doc__ |
| 593 | |
| 594 | def do_continue(self, *args, **kwargs): |
| 595 | global count_continue |
| 596 | count_continue += 1 |
| 597 | return super(CustomPdb, self).do_continue(*args, **kwargs) |
| 598 | |
| 599 | def foo(): |
| 600 | print("print_from_foo") |
| 601 | |
| 602 | def test_1(): |
| 603 | i = 0 |
| 604 | print("hello17") |
| 605 | pytest.set_trace() |
| 606 | x = 3 |
| 607 | print("hello18") |
| 608 | |
| 609 | assert count_continue == 2, "unexpected_failure: %d != 2" % count_continue |
| 610 | pytest.fail("expected_failure") |
| 611 | """ |
| 612 | ) |
| 613 | child = pytester.spawn_pytest("--pdbcls=mytest:CustomPdb %s" % str(p1)) |
| 614 | child.expect(r"PDB set_trace \(IO-capturing turned off\)") |
| 615 | child.expect(r"\n\(Pdb") |
| 616 | child.sendline("debug foo()") |
| 617 | child.expect("ENTERING RECURSIVE DEBUGGER") |
| 618 | child.expect(r"\n\(\(Pdb") |
| 619 | child.sendline("c") |
| 620 | child.expect("LEAVING RECURSIVE DEBUGGER") |
| 621 | assert b"PDB continue" not in child.before |
| 622 | # No extra newline. |
| 623 | assert child.before.endswith(b"c\r\nprint_from_foo\r\n") |
| 624 |
nothing calls this directly
no test coverage detected