diff --git a/docs/notes/2.23.x.md b/docs/notes/2.23.x.md index 3270da0a9f4..5a179d1e6dc 100644 --- a/docs/notes/2.23.x.md +++ b/docs/notes/2.23.x.md @@ -134,6 +134,8 @@ Support documenting macro constants using `MY_CONSTANT: Annotated[some_type, Doc Fixed bug where files larger than 512KB were being materialized to a process's sandbox without write permissions if the file was only globbed by `output_directories=(".",)`. +Fixed bug where using `RuleRunner` in plugin tests caused `ValueError` that complains about not finding build root sentinel files. Note that you may have to adjust your tests to account for the new `BUILDROOT` file that `RuleRunner` now injects in the sandbox it creates for each test. For example, a test that uses a `**` glob might have to add `!BUILDROOT` to exclude the `BUILDROOT` file, or otherwise account for its presence when inspecting a sandbox or its digest. + ### Other minor tweaks The "Provided by" information in the documentation now correctly reflects the proper backend to enable to activate a certain feature. diff --git a/pants-plugins/pants_explorer/server/graphql/query/conftest.py b/pants-plugins/pants_explorer/server/graphql/query/conftest.py index 1d23cc8bc24..61b073c2055 100644 --- a/pants-plugins/pants_explorer/server/graphql/query/conftest.py +++ b/pants-plugins/pants_explorer/server/graphql/query/conftest.py @@ -42,16 +42,20 @@ def all_help_info(rule_runner: RuleRunner) -> AllHelpInfo: def fake_consumed_scopes_mapper(scope: str) -> tuple[str, ...]: return ("somescope", f"used_by_{scope or 'GLOBAL_SCOPE'}") - return HelpInfoExtracter.get_all_help_info( - options=rule_runner.options_bootstrapper.full_options( - rule_runner.build_config, union_membership=UnionMembership({}) - ), - union_membership=rule_runner.union_membership, - consumed_scopes_mapper=fake_consumed_scopes_mapper, - registered_target_types=RegisteredTargetTypes.create(rule_runner.build_config.target_types), - build_symbols=BuildFileSymbolsInfo.from_info(), - build_configuration=rule_runner.build_config, - ) + with rule_runner.pushd(): + all_help_info = HelpInfoExtracter.get_all_help_info( + options=rule_runner.options_bootstrapper.full_options( + rule_runner.build_config, union_membership=UnionMembership({}) + ), + union_membership=rule_runner.union_membership, + consumed_scopes_mapper=fake_consumed_scopes_mapper, + registered_target_types=RegisteredTargetTypes.create( + rule_runner.build_config.target_types + ), + build_symbols=BuildFileSymbolsInfo.from_info(), + build_configuration=rule_runner.build_config, + ) + return all_help_info @pytest.fixture diff --git a/pants-plugins/pants_explorer/server/graphql/query/targets.py b/pants-plugins/pants_explorer/server/graphql/query/targets.py index e60f94e2304..2a8687bfad2 100644 --- a/pants-plugins/pants_explorer/server/graphql/query/targets.py +++ b/pants-plugins/pants_explorer/server/graphql/query/targets.py @@ -18,7 +18,14 @@ from pants.help.help_info_extracter import TargetTypeHelpInfo from pants.util.strutil import softwrap -specs_parser = SpecsParser() +_specs_parser: SpecsParser | None = None + + +def _get_specs_parser() -> SpecsParser: + global _specs_parser + if _specs_parser is None: + _specs_parser = SpecsParser() + return _specs_parser @strawberry.type(description="Describes a target field type.") @@ -165,7 +172,7 @@ def target_types( async def targets(self, info: Info, query: Optional[TargetsQuery] = None) -> List[Target]: req = GraphQLContext.request_state_from_info(info).product_request specs = ( - specs_parser.parse_specs( + _get_specs_parser().parse_specs( query.specs, description_of_origin="GraphQL targets `query.specs`" ) if query is not None and query.specs diff --git a/pants-plugins/pants_explorer/server/graphql/query/targets_test.py b/pants-plugins/pants_explorer/server/graphql/query/targets_test.py index 9194b6d4004..4dfedceb896 100644 --- a/pants-plugins/pants_explorer/server/graphql/query/targets_test.py +++ b/pants-plugins/pants_explorer/server/graphql/query/targets_test.py @@ -39,9 +39,13 @@ async def test_targets_query( "src/test/Dockerfile": "", } ) - actual_result = await schema.execute( - queries, variable_values=variables, context_value=context, operation_name="TestTargetsQuery" - ) + with rule_runner.pushd(): + actual_result = await schema.execute( + queries, + variable_values=variables, + context_value=context, + operation_name="TestTargetsQuery", + ) assert actual_result.errors is None assert actual_result.data == expected_data diff --git a/src/python/pants/backend/project_info/BUILD b/src/python/pants/backend/project_info/BUILD index b14525f43fe..558b0c5df43 100644 --- a/src/python/pants/backend/project_info/BUILD +++ b/src/python/pants/backend/project_info/BUILD @@ -3,4 +3,10 @@ python_sources() -python_tests(name="tests", timeout=180) +python_tests( + name="tests", + timeout=180, + overrides={ + "list_targets_test.py": {"dependencies": ["//BUILD_ROOT:files"]}, + }, +) diff --git a/src/python/pants/backend/project_info/dependencies_test.py b/src/python/pants/backend/project_info/dependencies_test.py index fd260ee9e1f..971e9249720 100644 --- a/src/python/pants/backend/project_info/dependencies_test.py +++ b/src/python/pants/backend/project_info/dependencies_test.py @@ -109,11 +109,12 @@ def assert_dependencies( assert json.loads(result.stdout) == expected else: assert not result.stdout - with open(output_file) as f: - if output_format == DependenciesOutputFormat.text: - assert f.read().splitlines() == expected - elif output_format == DependenciesOutputFormat.json: - assert json.load(f) == expected + with rule_runner.pushd(): + with open(output_file) as f: + if output_format == DependenciesOutputFormat.text: + assert f.read().splitlines() == expected + elif output_format == DependenciesOutputFormat.json: + assert json.load(f) == expected def test_no_target(rule_runner: PythonRuleRunner) -> None: diff --git a/src/python/pants/backend/project_info/dependents_test.py b/src/python/pants/backend/project_info/dependents_test.py index 3cb4d781a22..51b4cad464c 100644 --- a/src/python/pants/backend/project_info/dependents_test.py +++ b/src/python/pants/backend/project_info/dependents_test.py @@ -65,11 +65,12 @@ def assert_dependents( assert json.loads(result.stdout) == expected else: assert not result.stdout - with open(output_file) as f: - if output_format == DependentsOutputFormat.text: - assert f.read().splitlines() == expected - elif output_format == DependentsOutputFormat.json: - assert json.load(f) == expected + with rule_runner.pushd(): + with open(output_file) as f: + if output_format == DependentsOutputFormat.text: + assert f.read().splitlines() == expected + elif output_format == DependentsOutputFormat.json: + assert json.load(f) == expected def test_no_targets(rule_runner: RuleRunner) -> None: diff --git a/src/python/pants/backend/tools/taplo/rules_integration_test.py b/src/python/pants/backend/tools/taplo/rules_integration_test.py index ecb88dee5cc..28aa9187311 100644 --- a/src/python/pants/backend/tools/taplo/rules_integration_test.py +++ b/src/python/pants/backend/tools/taplo/rules_integration_test.py @@ -42,7 +42,7 @@ def run_taplo( rule_runner.set_options( ["--backend-packages=pants.backend.tools.taplo", *(extra_args or ())], ) - snapshot = rule_runner.request(Snapshot, [PathGlobs(["**"])]) + snapshot = rule_runner.request(Snapshot, [PathGlobs(["**", "!BUILDROOT"])]) partition = rule_runner.request( Partitions[Any], [TaploFmtRequest.PartitionRequest(snapshot.files)] )[0] diff --git a/src/python/pants/base/BUILD b/src/python/pants/base/BUILD index 614049541d9..98d5695f9e3 100644 --- a/src/python/pants/base/BUILD +++ b/src/python/pants/base/BUILD @@ -6,7 +6,9 @@ python_sources() python_tests( name="tests", sources=["*_test.py", "!exception_sink_test.py", "!*_integration_test.py"], - dependencies=["//BUILD_ROOT:files"], + overrides={ + "build_root_test.py": {"dependencies": ["//BUILD_ROOT:files"]}, + }, ) python_tests( diff --git a/src/python/pants/bsp/testutil.py b/src/python/pants/bsp/testutil.py index 3f39acd0dc0..f974ddedf58 100644 --- a/src/python/pants/bsp/testutil.py +++ b/src/python/pants/bsp/testutil.py @@ -95,7 +95,7 @@ def setup_bsp_server( notification_names = notification_names or set() thread_locals = PyThreadLocals.get_for_current_thread() - with setup_pipes() as pipes: + with setup_pipes() as pipes, rule_runner.pushd(): context = BSPContext() rule_runner.set_session_values({BSPContext: context}) conn = BSPConnection( diff --git a/src/python/pants/core/goals/BUILD b/src/python/pants/core/goals/BUILD index 37ae8dbc2d3..469511161ee 100644 --- a/src/python/pants/core/goals/BUILD +++ b/src/python/pants/core/goals/BUILD @@ -3,7 +3,13 @@ python_sources() -python_tests(name="tests", sources=["*_test.py", "!*_integration_test.py"]) +python_tests( + name="tests", + sources=["*_test.py", "!*_integration_test.py"], + overrides={ + "publish_test.py": {"timeout": 70}, + }, +) python_tests( name="integration", diff --git a/src/python/pants/core/goals/check_test.py b/src/python/pants/core/goals/check_test.py index 1be684cd3c4..ebbfc5d28fc 100644 --- a/src/python/pants/core/goals/check_test.py +++ b/src/python/pants/core/goals/check_test.py @@ -31,7 +31,7 @@ ) from pants.engine.target import FieldSet, MultipleSourcesField, Target, Targets from pants.engine.unions import UnionMembership -from pants.testutil.option_util import create_options_bootstrapper, create_subsystem +from pants.testutil.option_util import create_subsystem from pants.testutil.rule_runner import MockGet, RuleRunner, mock_console, run_rule_with_mocks from pants.util.logging import LogLevel from pants.util.meta import classproperty @@ -157,8 +157,8 @@ def run_typecheck_rule( ) -> Tuple[int, str]: union_membership = UnionMembership({CheckRequest: request_types}) check_subsystem = create_subsystem(CheckSubsystem, only=only or []) - with mock_console(create_options_bootstrapper(["-lwarn"])) as (console, stdio_reader): - rule_runner = RuleRunner() + rule_runner = RuleRunner(bootstrap_args=["-lwarn"]) + with mock_console(rule_runner.options_bootstrapper) as (console, stdio_reader): result: Check = run_rule_with_mocks( check, rule_args=[ diff --git a/src/python/pants/core/goals/export_test.py b/src/python/pants/core/goals/export_test.py index 2a99b88eb32..4146e9406a4 100644 --- a/src/python/pants/core/goals/export_test.py +++ b/src/python/pants/core/goals/export_test.py @@ -36,7 +36,7 @@ from pants.engine.rules import QueryRule from pants.engine.target import Target, Targets from pants.engine.unions import UnionMembership, UnionRule -from pants.testutil.option_util import create_options_bootstrapper, create_subsystem +from pants.testutil.option_util import create_subsystem from pants.testutil.rule_runner import ( MockEffect, MockGet, @@ -90,7 +90,7 @@ def run_export_rule(rule_runner: RuleRunner, targets: List[Target]) -> Tuple[int union_membership = UnionMembership({ExportRequest: [MockExportRequest]}) with open(os.path.join(rule_runner.build_root, "somefile"), "wb") as fp: fp.write(b"SOMEFILE") - with mock_console(create_options_bootstrapper()) as (console, stdio_reader): + with mock_console(rule_runner.options_bootstrapper) as (console, stdio_reader): digest = rule_runner.request(Digest, [CreateDigest([FileContent("foo/bar", b"BAR")])]) result: Export = run_rule_with_mocks( export, @@ -223,7 +223,7 @@ def test_warnings_for_non_local_target_environments( union_membership = UnionMembership({ExportRequest: [MockExportRequest]}) with open(os.path.join(rule_runner.build_root, "somefile"), "wb") as fp: fp.write(b"SOMEFILE") - with mock_console(create_options_bootstrapper()) as (console, stdio_reader): + with mock_console(rule_runner.options_bootstrapper) as (console, stdio_reader): digest = rule_runner.request(Digest, [CreateDigest([FileContent("foo/bar", b"BAR")])]) run_rule_with_mocks( export, diff --git a/src/python/pants/core/goals/publish_test.py b/src/python/pants/core/goals/publish_test.py index a389d5418cd..60ba1500571 100644 --- a/src/python/pants/core/goals/publish_test.py +++ b/src/python/pants/core/goals/publish_test.py @@ -183,9 +183,10 @@ def test_structured_output(rule_runner: RuleRunner) -> None: }, ] - with open("published.json") as fd: - data = json.load(fd) - assert data == expected + with rule_runner.pushd(): + with open("published.json") as fd: + data = json.load(fd) + assert data == expected @pytest.mark.skip("Can not run interactive process from test..?") diff --git a/src/python/pants/engine/BUILD b/src/python/pants/engine/BUILD index fd4c546cfe8..3a8c1c36dd1 100644 --- a/src/python/pants/engine/BUILD +++ b/src/python/pants/engine/BUILD @@ -8,6 +8,9 @@ python_tests( dependencies=["src/python/pants/engine/internals:fs_test_data"], sources=["*_test.py", "!streaming_workunit_handler_integration_test.py"], timeout=90, + overrides={ + "goal_test.py": {"dependencies": ["//BUILD_ROOT:files"]}, + }, ) python_tests( diff --git a/src/python/pants/engine/fs_test.py b/src/python/pants/engine/fs_test.py index 928856f276c..b3a88bc639c 100644 --- a/src/python/pants/engine/fs_test.py +++ b/src/python/pants/engine/fs_test.py @@ -112,6 +112,8 @@ def setup_fs_test_tar(rule_runner: RuleRunner) -> None: └── 2 c.ln -> a/b d.ln -> a + + NB: The RuleRunner injects a BUILDROOT file in the build_root. """ data = pkgutil.get_data("pants.engine.internals", "fs_test_data/fs_test.tar") assert data is not None @@ -123,6 +125,7 @@ def setup_fs_test_tar(rule_runner: RuleRunner) -> None: FS_TAR_ALL_FILES = ( + "BUILDROOT", # injected by RuleRunner, not present in tar "4.txt", "a/3.txt", "a/4.txt.ln", @@ -221,7 +224,10 @@ def test_path_globs_glob_pattern(rule_runner: RuleRunner) -> None: ) assert_path_globs(rule_runner, ["*/0.txt"], expected_files=[], expected_dirs=[]) assert_path_globs( - rule_runner, ["*"], expected_files=["4.txt"], expected_dirs=["a", "c.ln", "d.ln"] + rule_runner, + ["*"], + expected_files=["BUILDROOT", "4.txt"], + expected_dirs=["a", "c.ln", "d.ln"], ) assert_path_globs( rule_runner, @@ -302,7 +308,7 @@ def test_path_globs_ignore_pattern(rule_runner: RuleRunner) -> None: assert_path_globs( rule_runner, ["**", "!*.ln"], - expected_files=["4.txt", "a/3.txt", "a/b/1.txt", "a/b/2"], + expected_files=["BUILDROOT", "4.txt", "a/3.txt", "a/b/1.txt", "a/b/2"], expected_dirs=["a", "a/b"], ) @@ -318,7 +324,7 @@ def test_path_globs_ignore_sock(rule_runner: RuleRunner) -> None: assert_path_globs( rule_runner, ["**"], - expected_files=["non-sock.txt"], + expected_files=["BUILDROOT", "non-sock.txt"], expected_dirs=[], ) diff --git a/src/python/pants/engine/internals/BUILD b/src/python/pants/engine/internals/BUILD index f367f42787a..43030afe3f2 100644 --- a/src/python/pants/engine/internals/BUILD +++ b/src/python/pants/engine/internals/BUILD @@ -10,6 +10,7 @@ python_tests( sources=["*_test.py", "!scheduler_integration_test.py"], timeout=90, overrides={ + "engine_test.py": {"dependencies": ["//BUILD_ROOT:files"]}, "platform_rules_test.py": {"tags": ["platform_specific_behavior"], "timeout": 120}, }, ) diff --git a/src/python/pants/engine/internals/graph_test.py b/src/python/pants/engine/internals/graph_test.py index 32073ddfbbc..b7ef88a8224 100644 --- a/src/python/pants/engine/internals/graph_test.py +++ b/src/python/pants/engine/internals/graph_test.py @@ -1779,7 +1779,7 @@ class SingleSourceSubclass(SingleSourceField): HydratedSources, [HydrateSourcesRequest(valid_sources, for_sources_types=[SourcesSubclass])], ) - assert hydrated_valid_sources.snapshot.files == ("f1.f95",) + assert hydrated_valid_sources.snapshot.files == ("BUILDROOT", "f1.f95") assert hydrated_valid_sources.sources_type == SourcesSubclass valid_single_sources = SingleSourceSubclass("f1.f95", addr) diff --git a/src/python/pants/engine/internals/specs_rules_test.py b/src/python/pants/engine/internals/specs_rules_test.py index e544c6acd9b..aaf31c4877d 100644 --- a/src/python/pants/engine/internals/specs_rules_test.py +++ b/src/python/pants/engine/internals/specs_rules_test.py @@ -793,14 +793,21 @@ def assert_paths( ) assert_paths(["demo/*.foo", "-demo/unowned.foo"], set(), set()) - assert_paths([":"], {"f.txt"}, set()) + assert_paths([":"], {"BUILDROOT", "f.txt"}, set()) for dir_suffix in ("", ":"): assert_paths([f"unowned{dir_suffix}"], {"unowned/f.txt"}, {"unowned"}) assert_paths([f"demo{dir_suffix}"], {*all_expected_demo_files, "demo/BUILD"}, {"demo"}) assert_paths( ["::"], - {*all_expected_demo_files, "demo/BUILD", "f.txt", "unowned/f.txt", "unowned/subdir/f.txt"}, + { + *all_expected_demo_files, + "BUILDROOT", + "demo/BUILD", + "f.txt", + "unowned/f.txt", + "unowned/subdir/f.txt", + }, {"demo", "unowned", "unowned/subdir"}, ) assert_paths( diff --git a/src/python/pants/source/filespec_test.py b/src/python/pants/source/filespec_test.py index d6beac327ad..48e4fa71a71 100644 --- a/src/python/pants/source/filespec_test.py +++ b/src/python/pants/source/filespec_test.py @@ -48,7 +48,7 @@ def assert_rule_match( ("*/[be]*/b*", ("foo/bar/baz", "foo/bar/bar")), ("foo*/bar", ("foofighters/bar", "foofighters.venv/bar")), # Double stars. - ("**", ("a/b/c", "b")), + ("**", ("BUILDROOT", "a/b/c", "b")), ("a/**/f", ("a/f", "a/b/c/d/e/f")), ("a/b/**", ("a/b/d", "a/b/c/d/e/f")), # Dots. diff --git a/src/python/pants/testutil/BUILD b/src/python/pants/testutil/BUILD index da63ee45b78..c73b3375686 100644 --- a/src/python/pants/testutil/BUILD +++ b/src/python/pants/testutil/BUILD @@ -24,7 +24,6 @@ python_sources( "pants_integration_test.py": { "dependencies": ["//BUILD_ROOT:files", "src/python/pants/__main__.py"] }, - "rule_runner.py": {"dependencies": ["//BUILD_ROOT:files"]}, }, ) diff --git a/src/python/pants/testutil/rule_runner.py b/src/python/pants/testutil/rule_runner.py index a405e89fe4f..f3b8be43c01 100644 --- a/src/python/pants/testutil/rule_runner.py +++ b/src/python/pants/testutil/rule_runner.py @@ -31,6 +31,7 @@ overload, ) +from pants.base.build_environment import get_buildroot from pants.base.build_root import BuildRoot from pants.base.specs_parser import SpecsParser from pants.build_graph.build_configuration import BuildConfiguration @@ -310,17 +311,23 @@ def rewrite_rule_for_inherent_environment(rule): self.build_config = build_config_builder.create() self.environment = CompleteEnvironmentVars({}) - self.options_bootstrapper = self.create_options_bootstrapper(args=bootstrap_args, env=None) self.extra_session_values = extra_session_values or {} self.inherent_environment = inherent_environment self.max_workunit_verbosity = max_workunit_verbosity - options = self.options_bootstrapper.full_options( - self.build_config, - union_membership=UnionMembership.from_rules( - rule for rule in self.rules if isinstance(rule, UnionRule) - ), - ) - global_options = self.options_bootstrapper.bootstrap_options.for_global_scope() + + # Change cwd and add sentinel file (BUILDROOT) so NativeOptionParser can find build_root. + with self.pushd(): + Path("BUILDROOT").touch() + self.options_bootstrapper = self.create_options_bootstrapper( + args=bootstrap_args, env=None + ) + options = self.options_bootstrapper.full_options( + self.build_config, + union_membership=UnionMembership.from_rules( + rule for rule in self.rules if isinstance(rule, UnionRule) + ), + ) + global_options = self.options_bootstrapper.bootstrap_options.for_global_scope() dynamic_remote_options, _ = DynamicRemoteOptions.from_options(options, self.environment) local_store_options = LocalStoreOptions.from_options(global_options) @@ -398,7 +405,8 @@ def request(self, output_type: type[_O], inputs: Iterable[Any]) -> _O: if self.inherent_environment else Params(*inputs) ) - result = assert_single_element(self.scheduler.product_request(output_type, [params])) + with self.pushd(): + result = assert_single_element(self.scheduler.product_request(output_type, [params])) return cast(_O, result) def run_goal_rule( @@ -413,10 +421,11 @@ def run_goal_rule( merged_args = (*(global_args or []), goal.name, *(args or [])) self.set_options(merged_args, env=env, env_inherit=env_inherit) - raw_specs = self.options_bootstrapper.full_options_for_scopes( - [GlobalOptions.get_scope_info(), goal.subsystem_cls.get_scope_info()], - self.union_membership, - ).specs + with self.pushd(): + raw_specs = self.options_bootstrapper.full_options_for_scopes( + [GlobalOptions.get_scope_info(), goal.subsystem_cls.get_scope_info()], + self.union_membership, + ).specs specs = SpecsParser(root_dir=self.build_root).parse_specs( raw_specs, description_of_origin="RuleRunner.run_goal_rule()" ) @@ -424,19 +433,25 @@ def run_goal_rule( stdout, stderr = StringIO(), StringIO() console = Console(stdout=stdout, stderr=stderr, use_colors=False, session=self.scheduler) - exit_code = self.scheduler.run_goal_rule( - goal, - Params( - specs, - console, - Workspace(self.scheduler), - *([self.inherent_environment] if self.inherent_environment else []), - ), - ) + with self.pushd(): + exit_code = self.scheduler.run_goal_rule( + goal, + Params( + specs, + console, + Workspace(self.scheduler), + *([self.inherent_environment] if self.inherent_environment else []), + ), + ) console.flush() return GoalRuleResult(exit_code, stdout.getvalue(), stderr.getvalue()) + @contextmanager + def pushd(self): + with pushd(self.build_root): + yield + def create_options_bootstrapper( self, args: Iterable[str], env: Mapping[str, str] | None ) -> OptionsBootstrapper: @@ -465,7 +480,8 @@ def set_options( **{k: os.environ[k] for k in (env_inherit or set()) if k in os.environ}, **(env or {}), } - self.options_bootstrapper = self.create_options_bootstrapper(args=args, env=env) + with self.pushd(): + self.options_bootstrapper = self.create_options_bootstrapper(args=args, env=env) self.environment = CompleteEnvironmentVars(env) self._set_new_session(self.scheduler.scheduler) @@ -605,7 +621,7 @@ def write_digest( ) def run_interactive_process(self, request: InteractiveProcess) -> InteractiveProcessResult: - with pushd(self.build_root): + with self.pushd(): return native_engine.session_run_interactive_process( self.scheduler.py_session, request, @@ -778,14 +794,15 @@ def mock_console( *, stdin_content: bytes | str | None = None, ) -> Iterator[tuple[Console, StdioReader]]: - global_bootstrap_options = options_bootstrapper.bootstrap_options.for_global_scope() - colors = ( - options_bootstrapper.full_options_for_scopes( - [GlobalOptions.get_scope_info()], UnionMembership({}), allow_unknown_options=True + with pushd(get_buildroot()): + global_bootstrap_options = options_bootstrapper.bootstrap_options.for_global_scope() + colors = ( + options_bootstrapper.full_options_for_scopes( + [GlobalOptions.get_scope_info()], UnionMembership({}), allow_unknown_options=True + ) + .for_global_scope() + .colors ) - .for_global_scope() - .colors - ) with initialize_stdio(global_bootstrap_options), stdin_context( stdin_content diff --git a/src/python/pants/vcs/git_test.py b/src/python/pants/vcs/git_test.py index bca04d07907..843e4e85930 100644 --- a/src/python/pants/vcs/git_test.py +++ b/src/python/pants/vcs/git_test.py @@ -464,6 +464,7 @@ async def worktree_id_string() -> str: QueryRule(str, []), ] ) + rule_runner.build_root = origin.as_posix() rule_runner.set_options([], env_inherit={"PATH"}) worktree_id_1 = rule_runner.request(str, []) diff --git a/tests/python/pants_test/init/BUILD b/tests/python/pants_test/init/BUILD index 855f5cff7ca..213100394fb 100644 --- a/tests/python/pants_test/init/BUILD +++ b/tests/python/pants_test/init/BUILD @@ -11,7 +11,8 @@ python_tests( # These tests load `pants.toml`, which references many of these plugins. "src/python/pants/bin:plugins", ], - } + }, + "test_logging.py": {"dependencies": ["//BUILD_ROOT:files"]}, }, ) diff --git a/tests/python/pants_test/init/test_util.py b/tests/python/pants_test/init/test_util.py index 9016f0d9f42..934a6ae4d94 100644 --- a/tests/python/pants_test/init/test_util.py +++ b/tests/python/pants_test/init/test_util.py @@ -14,8 +14,8 @@ @contextmanager -def physical_workdir_base() -> Iterator[OptionValueContainer]: - with temporary_dir(cleanup=False) as physical_workdir_base: +def physical_workdir_base(rule_runner: RuleRunner) -> Iterator[OptionValueContainer]: + with temporary_dir(cleanup=False) as physical_workdir_base, rule_runner.pushd(): bootstrap_options = create_options_bootstrapper( [f"--pants-physical-workdir-base={physical_workdir_base}"] ).bootstrap_options.for_global_scope() @@ -42,7 +42,7 @@ def physical_workdir(pants_workdir: str, bootstrap_options: OptionValueContainer def test_init_workdir() -> None: rule_runner = RuleRunner() - with physical_workdir_base() as bootstrap_options: + with physical_workdir_base(rule_runner) as bootstrap_options: # Assert pants_workdir exists assert_exists(rule_runner.pants_workdir)