Skip to content

Fix exec_properties for py_test #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/pytest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ py_test(
"fixtures/*.json",
]),
env_inherit = ["FOO"],
exec_properties = {
"test.foo": "bar",
},
imports = ["../.."],
package_collisions = "warning",
pytest_main = True,
Expand Down
5 changes: 5 additions & 0 deletions py/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,17 @@ py_image_layer = _py_image_layer
resolutions = _resolutions

def _py_binary_or_test(name, rule, srcs, main, data = [], deps = [], resolutions = {}, **kwargs):
exec_properties = kwargs.pop("exec_properties", {})
non_test_exec_properties = {k: v for k, v in exec_properties.items() if not k.startswith("test.")}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clearly not ideal, im not sure forwarding everything is really the right move below, technically the new exec_group_compatible_with attr also would have this issue.


# Compatibility with rules_python, see docs in py_executable.bzl
main_target = "{}.find_main".format(name)
determine_main(
name = main_target,
target_name = name,
main = main,
srcs = srcs,
exec_properties = non_test_exec_properties,
**propagate_common_rule_attributes(kwargs)
)

Expand All @@ -80,6 +84,7 @@ def _py_binary_or_test(name, rule, srcs, main, data = [], deps = [], resolutions
deps = deps,
resolutions = resolutions,
package_collisions = package_collisions,
exec_properties = exec_properties,
**kwargs
)

Expand Down