Simulates pdbpp, which injects Pdb into do_debug, and uses self.__class__ in do_continue.
(self, pytester: Pytester)
| 601 | |
| 602 | @pytest.mark.xfail(reason="#10042", strict=False) |
| 603 | def test_pdb_with_injected_do_debug(self, pytester: Pytester) -> None: |
| 604 | """Simulates pdbpp, which injects Pdb into do_debug, and uses |
| 605 | self.__class__ in do_continue. |
| 606 | """ |
| 607 | p1 = pytester.makepyfile( |
| 608 | mytest=""" |
| 609 | import pdb |
| 610 | import pytest |
| 611 | |
| 612 | count_continue = 0 |
| 613 | |
| 614 | class CustomPdb(pdb.Pdb, object): |
| 615 | def do_debug(self, arg): |
| 616 | import sys |
| 617 | import types |
| 618 | |
| 619 | do_debug_func = pdb.Pdb.do_debug |
| 620 | |
| 621 | newglobals = do_debug_func.__globals__.copy() |
| 622 | newglobals['Pdb'] = self.__class__ |
| 623 | orig_do_debug = types.FunctionType( |
| 624 | do_debug_func.__code__, newglobals, |
| 625 | do_debug_func.__name__, do_debug_func.__defaults__, |
| 626 | ) |
| 627 | return orig_do_debug(self, arg) |
| 628 | do_debug.__doc__ = pdb.Pdb.do_debug.__doc__ |
| 629 | |
| 630 | def do_continue(self, *args, **kwargs): |
| 631 | global count_continue |
| 632 | count_continue += 1 |
| 633 | return super(CustomPdb, self).do_continue(*args, **kwargs) |
| 634 | |
| 635 | def foo(): |
| 636 | print("print_from_foo") |
| 637 | |
| 638 | def test_1(): |
| 639 | i = 0 |
| 640 | print("hello17") |
| 641 | pytest.set_trace() |
| 642 | x = 3 |
| 643 | print("hello18") |
| 644 | |
| 645 | assert count_continue == 2, "unexpected_failure: %d != 2" % count_continue |
| 646 | pytest.fail("expected_failure") |
| 647 | """ |
| 648 | ) |
| 649 | child = pytester.spawn_pytest(f"--pdbcls=mytest:CustomPdb {p1!s}") |
| 650 | child.expect(r"PDB set_trace \(IO-capturing turned off\)") |
| 651 | child.expect(r"\n\(Pdb") |
| 652 | child.sendline("debug foo()") |
| 653 | child.expect("ENTERING RECURSIVE DEBUGGER") |
| 654 | child.expect(r"\n\(\(Pdb") |
| 655 | child.sendline("c") |
| 656 | child.expect("LEAVING RECURSIVE DEBUGGER") |
| 657 | assert b"PDB continue" not in child.before |
| 658 | # No extra newline. |
| 659 | assert child.before.endswith(b"c\r\nprint_from_foo\r\n") |
| 660 |
nothing calls this directly
no test coverage detected