https://pantsbuild.org/ logo
#development
Title
# development
g

gentle-wolf-58752

12/16/2019, 7:42 PM
👋 hey all - working on adding to an existing console rule (
test
- adding an option to run within an interactive session) and am running into couple hiccups. Notably: • How to best mock out options being passed to a rule (using the
run_rule
test util, I didn’t catch anything in / after Erics change in https://github.com/pantsbuild/pants/pull/8742 that served as an example) • How to best constrain the rule to a single BFA when the option is provided (following https://github.com/pantsbuild/pants/pull/8586 it seems I could do this via specs, wasn’t sure if there was something more elegant)
👋 just wanted to call this out in case it was missed / folks have thoughts on it - both questions still stand (and I figured it might be easier to use Slack to discuss them v. doing it the PR)
h

hundreds-father-404

12/17/2019, 11:00 PM
For options, check the black tests to see how I constructed the options for a rule. I think that should work
Cc @hundreds-breakfast-49010 for the second question
g

gentle-wolf-58752

12/17/2019, 11:02 PM
I’ll look back at the black tests - iirc it doesn’t use the
run_rule
test helper
h

hundreds-father-404

12/17/2019, 11:07 PM
No, it doesn’t, but I believe constructing the option is the same
👀 1
g

gentle-wolf-58752

12/18/2019, 12:05 AM
Unless I’m missing something, there’s no option(s) passed in the
fmt
rule (or tests), and I wasn’t able to find any other rules that took options that were under tests. Failure on current tests looks like:
Copy code
ValueError: Rule expected to receive arguments of the form: (<class 'pants.engine.console.Console'>, <class 'pants.rules.core.test.TestOptions'>, pants.engine.addressable.BuildFileAddresses); got: [<pants.testutil.engine.util.MockConsole object at 0x112cdaa58>, (BuildFileAddress(some/target/BUILD, target),)]
So while the rule can fetch the options, it seems the
run_rule
helper can’t do the same (ie. can’t mock out a
Get
for the goal options). Using a simple
Mock
(for options) looks promising, currently swimming in errors around missing `MockGet`s - appreciate the insights / feedback in the meantime.
h

hundreds-father-404

12/18/2019, 12:15 AM
I’m on a bus and can’t look closely but we pass an option in the black tests for a config file and for
args
g

gentle-wolf-58752

12/18/2019, 12:19 AM
Ah, found it - looks like an integration test, thanks I’ll continue to dig