<#17860 Support customising behaviour of `test` go...
# github-notifications
q
#17860 Support customising behaviour of `test` goal Issue created by xlevus In two of my projects, I have come across a situation where additional setup is needed to be run before a test. Both cases have been very similar and roughly correlate to: 1. Package the tests relevant dependencies 2. Upload the result to a remote system (e.g. a remote PaaS, or a locally attached microcontroller) 3. Run the test against the remote system. 4. Tear down the changes to the remote system. In both of these cases, additional information needs to be passed to the tests. • For the remote PaaS, the tests need to know the URI of the created resource on the PaaS • For microcontrollers, the tests need to know which device to connect to In both of these cases, my current solution is to implement a
test-plus
goal which does the setup/teardown before running the normal
test
rules, it has the following shortfalls: • Copy-Pasted from the canonical implementation. • Non-Standard. Have to remember to run
./pants test-plus
instead of `./pants test • Built for a single task. (Admittedly, I could probably merge my implementations with some tactical Unions) • No mechanism for feeding additional information into the test. * alternatives considered* • Doing all this in the test framework • Pants-plugin is doing it already, would be duplicate effort • Defining a
X_on_Y
target and specifying
runtime_dependencies
. • This had the problem that
./pants package
would deploy the target (undesired) • Adding Pre/Post goal hooks. • my implementation was cumbersome. • required every goal to add call the pre-goal and post-goal rules. • Didn't necessarily make sense for every goal (i.e. micro-controller tests needed the device tty, what if you have multiple devices or targets?) • Why stop at goal? Why not add middleware to rules? Possibly another solution could be to have some sort of
TestContextRequest -> TestContext
rule that would return a digest and environment map. pantsbuild/pants