bazelbuild / bazelbuild/bazel

Some failed tests empties __init__.py

Open
#26,615 3 comments 1 reaction 0 assignees View on GitHub
type: bug untriaged
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the bug:

When tests are executed, some tests make Bazel delete content of the \_\_init\_\_.py. The file is still there, but completely empty.

It does not matter did test failed or succeeded, or is one or multiple tests executed. Note that project has multiple \_\_init\_\_.py files. It seems that only those related to a specific tests gets emptied.

I tried to make \_\_init\_\_.py read-only, but then I get
```
INFO: Analyzed target //project/tests:test1 (1 packages loaded, 10 targets configured).
ERROR: /project/tests/BUILD.bazel:20:8: Testing //project/tests:test1 failed: Could not copy inputs into sandbox: /home/user/.cache/bazel/_bazel_user/9818f85d6d55739b55c209aa3bbf3af7/sandbox/linux-sandbox/1034/execroot/_main/bazel-out/k8-fastbuild/bin/project/tests/test1.runfiles/_main/project/__init__.py (Permission denied)
Target //project/tests:test1 up-to-date:
bazel-bin/project/tests/test1
INFO: Elapsed time: 0.245s, Critical Path: 0.06s
INFO: 3 processes: 3 internal.
ERROR: Build did NOT complete successfully
//projects/tests:test1 NO STATUS
```

### Which category does this issue belong to?

Python Rules

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

It randomly happens for some tests.

### Which operating system are you running Bazel on?

Fedora Linux 42 (Workstation Edition)

### What is the output of `bazel info release`?

release 8.3.1

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

_No response_

### What's the output of `git remote get-url origin; git rev-parse HEAD` ?

```text
git@gitlab:user/project.git
268a58ffbede521422581f91865ef33d8e8d1c01

(obfuscated)
```

### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.

_No response_

### Have you found anything relevant by searching the web?

_No response_

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

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the Bazel target //project/tests:test1 from project/tests/BUILD.bazel, using Bazel 8.3.1 on Fedora Linux. Inspect the generated runfiles and the related Python rules to determine why project/__init__.py is emptied during test execution. Done means a reproducible test case and a fix that preserves all affected __init__.py contents while tests run normally.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.