Skip to content

[Bug]: py_test targets cannot start with test_ if using pytest_main = True #723

@hofbi

Description

@hofbi

What happened?

When using pytest_main = True on py_test, my test target cannot start with test_. If it does, I get E ModuleNotFoundError: No module named 'test_foo'. See #722 as a reproducer.

Version

Development (host) and target OS/architectures:

Output of bazel --version: 8.4.0 (version used in this repo)

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file: main of this repo

Language(s) and/or frameworks involved:

How to reproduce

# Checkout https://github.com/aspect-build/rules_py/pull/722
bazel test //examples/pytest:test_foo

Any other information?

Why is this important?

The simple answer is of course to just choose a different name for the targets. However, test_ is a very common pattern in Python for naming unit test files. Now if autogenerating the targets with gazelle, we would also expect to see a target with the same name which is not possible in this case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions