<@U051221NF>: any advice on how to handle `RuleRun...
# development
f
@happy-kitchen-89482: any advice on how to handle
RuleRunner.do_not_use_mock
in a world of call-by-name rules? https://github.com/pantsbuild/pants/blob/2289117d3bf6268f8a1707e5bac2918df8055317/src/python/pants/testutil/rule_runner.py#L629
The existing implementation invokes
RuleRunner.request
to get the unmocked value. We would likely need a call-by-name sync invocation API to support that kind of use. Instead, I'm leaning toward either the function for the mock_call returning a "run original call" sentinel or just setting the function value in the
mock_calls
to a similar sentinel.
RuleRunner
would then just avoid using a mock for that call. Thoughts?
(Relevant test is core export_test which uses
do_not_use_mock
.)
PyGeneratorResponseCall
appears to have
input_types
and
output_type
attributes so invoking
RuleRunner.request
might work.
Or I could just pass the precise types to
do_not_use_mock
as it expects.
h
Funny, I was looking at this area of rule_runner.py yesterday.
Yeah, we might need an equivalent of
request()
for call-by-name to support this, and other uses
But since we know the name of the original function, maybe it’s not that complicated? We could support the keys in
mock_calls
being not strings but actual function references, to make this easier?
f
This seemed to work:
Copy code
diff --git a/src/python/pants/core/goals/export_test.py b/src/python/pants/core/goals/export_test.py
index c0017134a5..2f97f8d82f 100644
--- a/src/python/pants/core/goals/export_test.py
+++ b/src/python/pants/core/goals/export_test.py
@@ -146,6 +146,9 @@ def run_export_rule(
                 DistDir(relpath=Path("dist")),
                 create_subsystem(ExportSubsystem, resolve=resolves, bin=binaries),
             ],
+            mock_calls={
+                "pants.engine.intrinsics.add_prefix": lambda *xs: rule_runner.request(Digest, xs),
+            },
             mock_gets=[
                 MockGet(
                     output_type=ExportResults,
so basically the same as what
do_not_use_mock
does
h
Yeah but that won’t work once we remove by-type support
I guess we have plenty of time to worry about that