Skip to content

Commit a01323e

Browse files
authored
Fix py_test with nested target name (#485)
Fixes #483
1 parent 2dd9632 commit a01323e

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

examples/pytest/BUILD.bazel

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,21 @@ py_test(
2222
"@pypi_pytest//:pkg",
2323
],
2424
)
25+
26+
py_test(
27+
name = "nested/pytest",
28+
srcs = [
29+
"foo_test.py",
30+
":__test__",
31+
],
32+
env_inherit = ["FOO"],
33+
imports = ["../.."],
34+
main = ":__test__.py",
35+
package_collisions = "warning",
36+
deps = [
37+
":__test__",
38+
"@pypi_ftfy//:pkg",
39+
"@pypi_neptune//:pkg",
40+
"@pypi_pytest//:pkg",
41+
],
42+
)

py/private/py_binary.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ def _py_binary_rule_impl(ctx):
3232
# each segment from site-packages in the venv to the root of the runfiles tree.
3333
# Five .. will get us back to the root of the venv:
3434
# {name}.runfiles/.{name}.venv/lib/python{version}/site-packages/first_party.pth
35-
escape = "/".join(([".."] * 4))
35+
# If the target is defined with a slash, it adds to the level of nesting
36+
target_depth = len(ctx.label.name.split("/")) - 1
37+
escape = "/".join(([".."] * (4 + target_depth)))
3638

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

0 commit comments

Comments
 (0)