(pyfile, target, run)
| 613 | |
| 614 | @pytest.mark.parametrize("run", runners.all_launch) |
| 615 | def test_subprocess_with_parent_pid(pyfile, target, run): |
| 616 | @pyfile |
| 617 | def child(): |
| 618 | import sys |
| 619 | |
| 620 | assert "debugpy" in sys.modules |
| 621 | |
| 622 | import debugpy |
| 623 | |
| 624 | assert debugpy # @bp |
| 625 | |
| 626 | @pyfile |
| 627 | def parent(): |
| 628 | import debuggee |
| 629 | import os |
| 630 | import subprocess |
| 631 | import sys |
| 632 | |
| 633 | import debugpy |
| 634 | |
| 635 | debuggee.setup() |
| 636 | |
| 637 | # Running it through a shell is necessary to ensure the |
| 638 | # --parent-session-pid option is tested and the underlying |
| 639 | # Python subprocess can associate with this one's debug session. |
| 640 | if sys.platform == "win32": |
| 641 | argv = ["cmd.exe", "/c"] |
| 642 | else: |
| 643 | argv = ["/bin/sh", "-c"] |
| 644 | |
| 645 | cli_opts = debugpy.get_cli_options() |
| 646 | assert cli_opts, "No CLI options found" |
| 647 | |
| 648 | host, port = cli_opts.address |
| 649 | access_token = cli_opts.adapter_access_token |
| 650 | |
| 651 | shell_args = [ |
| 652 | sys.executable, |
| 653 | "-m", |
| 654 | "debugpy", |
| 655 | "--connect", f"{host}:{port}", |
| 656 | "--parent-session-pid", str(os.getpid()), |
| 657 | "--adapter-access-token", access_token, |
| 658 | sys.argv[1], |
| 659 | ] |
| 660 | argv.append(" ".join(shell_args)) |
| 661 | |
| 662 | subprocess.check_call(argv, env=os.environ | {"DEBUGPY_RUNNING": "false"}) |
| 663 | |
| 664 | with debug.Session() as parent_session: |
| 665 | with run(parent_session, target(parent, args=[child])): |
| 666 | parent_session.set_breakpoints(child, all) |
| 667 | |
| 668 | with parent_session.wait_for_next_subprocess() as child_session: |
| 669 | expected_child_config = expected_subprocess_config(parent_session) |
| 670 | child_config = child_session.config |
| 671 | child_config.pop("isOutputRedirected", None) |
| 672 | assert child_config == expected_child_config |
nothing calls this directly
no test coverage detected
searching dependent graphs…