bazelbuild / rules_python

Bazel Python Rules
https://rules-python.readthedocs.io
Apache License 2.0
516 stars 532 forks source link

Exec py_test targets in a way that would work with --run_under=lldb #2104

Open keith opened 1 month ago

keith commented 1 month ago

🚀 feature request

Description

When you're debugging python targets that load python C extensions, it can be useful in general to run something like lldb -- python3 -m pytest path/to/tests. In bazel I would envision this as bazel test --run_under=lldb :tests, but this doesn't work currently since py_test execs a script with a shebang. I think in theory if py_test ran the equivalent of python3 path/to/script it could "just work" but I'm not sure.

Describe alternatives you've considered

You can try to catch the process by launching the debugger elsewhere like lldb --wait-for -n python3.11, but this is a bit fragile since you could catch the wrong process

aignas commented 1 month ago

idea 1 - running the command lldb -- python3 -m pytest path/to/tests

A few thoughts, since we need the $(PYTHON3) interpreter reference in most of the commands here and we may also need to execute pytest as part of the command line, it does feel like passing --run_under may be insufficient. The tools that we pass may need to be accessed via labels and I am wondering if the approach described here can be extended to also change the actual entry point that is executed for the tests.

lldb could be a common enough scenario that could be enabled via a build configuration change.

idea 2 - running lldb Githubissues.
  • Githubissues is a development platform for aggregating issues.