From 71cb373178b2ebdc687cc40361dc0078ddfb61d9 Mon Sep 17 00:00:00 2001 From: Gabriel Russo Date: Wed, 7 Jan 2026 19:38:10 +0000 Subject: [PATCH] Allow pytest tests to be named test_ --- examples/pytest/BUILD.bazel | 2 +- py/defs.bzl | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/pytest/BUILD.bazel b/examples/pytest/BUILD.bazel index 264aaebf..c8bfedc2 100644 --- a/examples/pytest/BUILD.bazel +++ b/examples/pytest/BUILD.bazel @@ -7,7 +7,7 @@ py_library( ) py_test( - name = "pytest_test", + name = "test_pytest_test", srcs = ["foo_test.py"], data = glob([ "fixtures/*.json", diff --git a/py/defs.bzl b/py/defs.bzl index bc9ff216..f60a69c3 100644 --- a/py/defs.bzl +++ b/py/defs.bzl @@ -140,7 +140,8 @@ def py_test(name, srcs = [], main = None, pytest_main = False, **kwargs): if pytest_main: if main: fail("When pytest_main is set, the main attribute should not be set.") - pytest_main_target = name + ".pytest_main" + # Add a prefix to the test main to ensure targets called "test_*" do not get discovered by pytest. + pytest_main_target = "zzz_" + name + ".pytest_main" main = pytest_main_target + ".py" py_pytest_main(name = pytest_main_target) srcs.append(main)