Skip to content

Commit

Permalink
Fix py_test with nested target name
Browse files Browse the repository at this point in the history
Fixes #483
  • Loading branch information
keith committed Dec 16, 2024
1 parent 0b3c298 commit ce7ed5c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
18 changes: 18 additions & 0 deletions examples/pytest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,21 @@ py_test(
"@pypi_pytest//:pkg",
],
)

py_test(
name = "nested/pytest",
srcs = [
"foo_test.py",
":__test__",
],
env_inherit = ["FOO"],
imports = ["../.."],
main = ":__test__.py",
package_collisions = "warning",
deps = [
":__test__",
"@pypi_ftfy//:pkg",
"@pypi_neptune//:pkg",
"@pypi_pytest//:pkg",
],
)
4 changes: 3 additions & 1 deletion py/private/py_binary.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ def _py_binary_rule_impl(ctx):
# each segment from site-packages in the venv to the root of the runfiles tree.
# Five .. will get us back to the root of the venv:
# {name}.runfiles/.{name}.venv/lib/python{version}/site-packages/first_party.pth
escape = "/".join(([".."] * 4))
# If the target is defined with a slash, it adds to the level of nesting
target_depth = len(ctx.label.name.split("/")) - 1
escape = "/".join(([".."] * (4 + target_depth)))

# A few imports rely on being able to reference the root of the runfiles tree as a Python module,
# the common case here being the @rules_python//python/runfiles target that adds the runfiles helper,
Expand Down

0 comments on commit ce7ed5c

Please sign in to comment.