Skip to content

py_test debugging fails with --nobuild_runfile_links set #7788

@jlamberts-yobi

Description

@jlamberts-yobi

Description of the bug:

We set common --nobuild_runfile_links in our .bazelrc. This causes the IntelliJ debugger with the python plugin to break with the error AssertionError: Cannot find .runfiles directory for py_test targets. Removing that line from .bazelrc fixes the issue, but we'd prefer to keep it for regular builds.

From what we can tell this is because running in debug mode triggers a custombazel build command instead of a bazel test; maybe adding --build_runfile_links to that command would fix it?:

bazel build --tool_tag=ijwb:IDEA:community --color=yes --progress_in_terminal_title=no --build_event_binary_file=/path/to/some/binary/file --nobuild_event_binary_file_path_conversion --build_event_publish_all_actions -- //my/build/target:my_py_test

Which category does this issue belong to?

Intellij

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

Add this to your .bazelrc

common --nobuild_runfile_links

create a build file containing this

py_test(
    name = "test",
    srcs = ["test.py"],
)

and a test file containing this:

import unittest

class SmokeTest(unittest.TestCase):

    def test_ok(self):
        self.assertTrue(True)

    def test_fail(self):
        self.fail()

if __name__ == '__main__':
    unittest.main()

If you run the test it should run as normal. However, if you debug the test using the built in debugger it should error out before reaching the test.

If you comment out that line from your bazelrc it should work as expected.

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

IntelliJ IDEA 2025.1.1.1 (Community Edition)

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

Python 3.12.3

What Bazel plugin version are you using?

2025.06.10.0.1-api-version-251

Have you found anything relevant by searching the web?

Didn't see any similar issues reporting the same thing, just some reporting hanging during debugging which isn't the problem here.

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

No response

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Untriaged

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions