<#22440 Allow passing runnable_dependencies to all...
# github-notifications
c
#22440 Allow passing runnable_dependencies to all test targets (python_tests, etc.) Issue created by huonw Is your feature request related to a problem? Please describe. Sometimes a test needs to execute an external binary, whether an artifact built from the repo or something installed on the system. For instance, at work, we have tests that run database migrations, then execute
pg_dump
, to test Postgres' view of the final database schema. This has overlap with the
runtime_package_dependencies
field, especially if wanting to execute an artifact build from the repo. However, that's not a complete solution: • it doesn't work with
system_binary
• it will only provide the package output as a file, it won't necessarily be executable (e.g. if the package needs to run on a specific Python version, which may not be available within the test sandbox) Describe the solution you'd like Similar to
test_shell_command
(and
adhoc_tool
) add a
runnable_dependencies
field to
python_test
. For instance: # BUILD system_binary(name="pg_dump, binary_name="pg_dump", ...) python_test(name="test", source="test_foo.py", runnable_dependencies=[":pg_dump"]) # test_foo.py def test_the_thing(): subprocess.run(["pg_dump", ...]) Currently, we need to either pass the whole
PATH
into the test (reducing hermeticity), or do a work around like
export PG_DUMP_PATH=$(which pg_dump)
in
.pants.bootstrap
+
python_test(..., extra_env_vars=["PG_DUMP_PATH"])
+
subprocess.run([os.environ["PG_DUMP_PATH"], ...])
. Describe alternatives you've considered N/A Additional context Potentially clarifying the roles and behaviours of the various
dependencies
fields on tests be helpful (e.g. why can't test target's
dependencies
just allow packaged targets directly, and thus behave more like
execution_dependencies
). pantsbuild/pants