Skip to content

Commit fb615a4

Browse files
Add a test case for Pants integration testing docs (#20451)
1 parent bcd3d63 commit fb615a4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/docs/writing-plugins/the-rules-api/testing-plugins.mdx

+30
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,36 @@ def test_build_ignore_dependency() -> None:
552552

553553
`run_pants()` is hermetic by default, meaning that it will not read your `pants.toml`. As a result, you often need to include the option `--backend-packages` in the arguments to `run_pants()`. You can alternatively set the argument `hermetic=False`, although we discourage this.
554554

555+
For example:
556+
557+
```python
558+
from pants.testutil.pants_integration_test import run_pants, setup_tmpdir
559+
560+
561+
def test_getting_list_of_files_from_a_target() -> None:
562+
sources = {
563+
"dir/BUILD": "files(sources=['subdir/*.txt'])",
564+
"dir/subdir/file1.txt": "",
565+
"dir/subdir/file2.txt": "",
566+
}
567+
with setup_tmpdir(sources) as tmpdir:
568+
result = run_pants(
569+
[
570+
"--backend-packages=['pants.backend.python']",
571+
"filedeps",
572+
f"{tmpdir}/dir:",
573+
],
574+
)
575+
result.assert_success()
576+
assert all(
577+
filepath in result.stdout
578+
for filepath in (
579+
f"{tmpdir}/dir/subdir/file1.txt",
580+
f"{tmpdir}/dir/subdir/file2.txt",
581+
)
582+
)
583+
```
584+
555585
To read any files that were created, use `get_buildroot()` as the first part of the path to ensure that the correct directory is read.
556586

557587
```python

0 commit comments

Comments
 (0)