aloof-angle-91616
08/24/2020, 3:05 AMintegration tests for Pantsthis isn't 100% clear imho. perhaps "integration test for pants plugin code"?
hundreds-father-404
08/24/2020, 3:09 AMcould we consider explicitly just sort of using your four-word descriptions as the snake-cased method names directlyPossibly. Related is that we need to answer where the utils live, also, e.g. *
testutil/rule_unit_tests.py
* testutil/rule_integration_test.py
But then I didn’t like this at all:
from pants.testutil.rule_integration_test import RuleRunner
It’s not predictable. I’m pretty sure that we want to call this type RuleRunner.
Which led to me thinking we have
from pants.testutil.rule_runner import RuleRunner
def test() -> None:
  RuleRunner.run_rule_with_mocks(foo, gets=MockGet(...))
// or
def test(rule_runner: RuleRunner) -> None:
   rule_runner.request_product(P, [S])aloof-angle-91616
08/24/2020, 3:10 AMaloof-angle-91616
08/24/2020, 3:10 AMRuleRunnerhundreds-father-404
08/24/2020, 3:13 AMi personally prefer the explicit injection of RuleRunnerThis is the part I don’t love about my proposal. With
run_rule / aka RuleRunner.run_rule_with_mocks(), you do not want to have to actually create an instance of RuleRunner. That’s more setup than you’d like, and run_rule() will ignore all that setup. It’s a classmethod for that reason, so you would not have it injected via a fixture
But that’s really subtle, and I could see plugin authors unintentionally doing more work than they really need tohundreds-father-404
08/24/2020, 3:13 AMrun_rule() should probably be a separate file from TestBase / aka RuleRunner.
But run_rule() now needs a new namealoof-angle-91616
08/24/2020, 3:13 AMaloof-angle-91616
08/24/2020, 3:15 AMexecute_rule() or simulate_rule() perhaps?hundreds-father-404
08/24/2020, 3:17 AMsimulate_rule(), I think! The tricky thing is it does actually execute your rule, just not any of the things outside your rule like `Get`s and the inputs to your rulehundreds-father-404
08/24/2020, 3:18 AMrun_rule_with_mocks(). Maybe execute_rule_with_mocks()? Does that still live in engine_util.py?
testutil/
  engine_util.py
  rule_runner.py
  pants_integration_test.py
  option_util.pyaloof-angle-91616
08/24/2020, 3:18 AMaloof-angle-91616
08/24/2020, 3:19 AMrun_rule_with_mocks() method. i think your 1/2/3/4 classification makes sensehundreds-father-404
08/24/2020, 3:19 AMengine_util.execute_rule_with_mocks() would be the least used of the 4 approaches, as that’s not super discoverable. But also honestly maybe not a huge deal.
I suspect after writing these plugin docs that the vast majority of plugin authors will want approaches #3 and #4
In our own repo, run_rule() is really only useful for our highly generic rules like test.py and lint.pyaloof-angle-91616
08/24/2020, 3:20 AMIn our own repo, run_rule() is really only useful for our highly generic rules like test.py and lint.pythat's a great point and should maybe be included in docs if not already??
hundreds-father-404
08/24/2020, 3:21 AMpants_run() is the first that’s seen lots of love, and today’s changes were for TestBasehundreds-father-404
08/24/2020, 3:22 AMRuleRunner! I’m going on a 4 day roadtrip (flying for the first part to get the car), and might finish the prototype on the flight tomorrowhundreds-father-404
08/28/2020, 7:23 PMrun_rule_with_mocks() as a top-level function in rule_runner.py. So you could have this:
from pants.testutil.rule_runner import RuleRunner, run_rule_with_mocks
@pytest.fixture
def rule_runner() -> RuleRunner:
    return RuleRunner(rules=[...])
def test_foo() -> None:
      result = run_rule_with_mocks(my_rule, inputs=[...], mock_gets=[...])
def test_bar(rule_runner: RuleRunner) -> None:
    result = rule_runner.request_product(P, [s1, s2])