Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Gazelle not raising error when a target py_test exists in place of a py_binary

Đang mở
#3,603 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
48/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
build-system

Hướng nghiên cứu

Bắt đầu tại entry point của rules_python_gazelle_plugin xử lý các target được sinh ra bị xung đột, sử dụng reproduction lib/demo được cung cấp và lệnh bazel run //:gazelle -- -strict -mode fix. So sánh xung đột giữa py_binary và py_test với trường hợp py_library và py_test. Được xem là hoàn tất khi xung đột py_binary được báo cáo là lỗi và lệnh thoát với status 1, nhất quán với xung đột còn lại.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

🐞 bug report

Affected Rule

rules_python_gazelle_plugin functionality

Is this a regression?

Still needs assessment

Description

When gazelle runs over a BUILD file and finds a py_test target where it wants to make a py_binary target, the gazelle extension flags the conflict, but it does not elevate to an error. This is not the case for other target conflicts. For example, if a py_test exists where a py_library should, a full error is raised and the exit code respects this.

When this conflict happens, no other gazelle edits are recommended for the affected target. Recommendations to other targets proceed as normal.

🔬 Minimal Reproduction

Make a simple tree like

lib/demo/
  - example_lib.py
  - example_bin.py
  - example_test.py

The contents of each are
example_bin.py

from lib.demo import example_lib


def main() -> None:
    print("Lib call:", example_lib.some_helper())


if __name__ == "__main__":
    main()

example_lib.py

def some_helper() -> int:
    return 52

example_test.py

import unittest

from lib.demo import example_lib


def test_thing() -> None:
    assert example_lib.some_helper() == 52


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

Now make the BUILD file with the following contents

load("@rules_python//python:defs.bzl", "py_library", "py_test")

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

py_library(
    name = "example_lib",
    srcs = ["example_lib.py"],
)

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

Run bazel run //:gazelle -- -strict -mode diff and see the following output

$ bazel run //:gazelle -- -strict -mode fix
(21:34:13) INFO: Current date is 2026-02-16
(21:34:13) INFO: Analyzed target //:gazelle (0 packages loaded, 0 targets configured).
(21:34:13) INFO: Found 1 target...
Target //:gazelle up-to-date:
  bazel-bin/gazelle-runner.bash
  bazel-bin/gazelle
(21:34:13) INFO: Elapsed time: 0.129s, Critical Path: 0.05s
(21:34:13) INFO: 1 process: 4 action cache hit, 1 internal.
(21:34:13) INFO: Build completed successfully, 1 total action
gazelle: failed to generate target "//lib/demo:example_bin" of kind "py_binary": a target of kind "py_test" with the same name already exists

Now notice the difference in error when py_library is converted incorrectly to a py_test.

gazelle: failed to generate target "//lib/demo:example_bin" of kind "py_binary": a target of kind "py_test" with the same name already exists
gazelle: ERROR: failed to generate target "//lib/demo:example_lib" of kind "py_library": a target of kind "py_test" with the same name already exists. Use the '# gazelle:python_library_naming_convention' directive to change the naming convention.

The details are the same, but the latter scenario is reflected in the exit code with a value of 1.

🌍 Your Environment

Operating System:
debian linux

Output of bazel version:
8.4.2

Rules_python version:
1.8.3

Ngôn ngữ chính
Starlark
Star
690
Fork
722
Merge trung bình
1 ngày 55 phút
Pull request đã merge (30 ngày)
38

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của bazel-contrib/rules_python

Tất cả issue của bazel-contrib/rules_python

Issue tương tự

Thêm issue về Build System

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.