bazelbuild / intellij

IntelliJ plugin for Bazel projects
https://ij.bazel.build/
Apache License 2.0
761 stars 304 forks source link

debugging py_test targets with pytest main "hangs" #6824

Open rajukrishnamurthy opened 1 week ago

rajukrishnamurthy commented 1 week ago

Description of the bug:

pytest targets executed with pytest.main() seems to hang, but appears to be running stat() every file in the filesystem. The debugging session doesn't ever start because there are inevitably unreadable files with throws errors.

Which category does this issue belong to?

Intellij, PyCharm

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

a minimal repo can be found here

If you debug the unit_test target, I am able to set successfully debug. However, if you try to debug the pytest_test target, it "hangs" on with the folllowing:

import sys; print('Python %s on %s' % (sys.version, sys.platform))
/usr/bin/python3 "/Users/rkrishnamurthy/Library/Application Support/JetBrains/IntelliJIdea2024.2/plugins/python-ce/helpers/pydev/pydevd.py" --multiprocess --qt-support=auto --client 127.0.0.1 --port 51013 --file /private/var/tmp/_bazel_rkrishnamurthy/5303facb39f6d1f7ffd509576224e2f0/execroot/videoamp/bazel-out/darwin_arm64-fastbuild/bin/demo/python/idea_debug/py/py_test
Connected to pydev debugger (build 242.23339.11)
============================= test session starts ==============================
platform darwin -- Python 3.9.18, pytest-7.0.1, pluggy-1.0.0
rootdir: /

if you pause/restart the debugging session a few times, there are repeated calls to Path.stat() in lib/python3.9/pathlib.py

Which Intellij IDE are you using? Please provide the specific version.

IDEA ultimate 2024.2.3

What programming languages and tools are you using? Please provide specific versions.

python 3.9 toolchain

What Bazel plugin version are you using?

2024.09.10.0.1-api-version-242

Have you found anything relevant by searching the web?

There is an ongoing slack thread, however, the ability to debug py_test targets is new, so I suspect people haven't run into this yet.

Any other information, logs, or outputs that you want to share?

No response

agluszak commented 1 week ago

Hey @rajukrishnamurthy, could you verify if #6847 fixes the issue for you?

rajukrishnamurthy commented 6 days ago

@agluszak I pulled down master built and installed the plugin and am getting the same behavior with the repo I referenced above.

tpasternak commented 5 days ago

Oh, just found we've already received this report in #5146

agluszak commented 3 days ago

@agluszak I pulled down master built and installed the plugin and am getting the same behavior with the repo I referenced above.

It's not merged yet, so you need to build branch agluszak/fix-6824

tpasternak commented 3 days ago

@rajukrishnamurthy I have merged that, you can try master branch now

rajukrishnamurthy commented 3 days ago

Apologies, I didn't look at that closely enough. Okay, with the fix in place it is no longer scanning the entire filesystem, however it doesn't seem to actually run the test. I've noticed a couple of things:

  1. when pytest.main() is called in my stripped down example, I can trace to pytest_cmdline_main return NO_TESTS_COLLECTED. Perhaps my main is incorrect?
  2. We override the py_test macro where we set environment variables args that we use to pass to pytest.main(). It seems to bypass that entirely and use the py_test from rules_python. I've added an example with an override of py_test defined here. This is probably a separate problem, but I imagine many people do this.

In both cases, bazel test runs the tests correctly.

I'm happy to continue to be a tester and I will try to be more timely in my response.

Thanks!