Skip to content

Commit 8f021a2

Browse files
committed
feat: Support reading file_or_dir args from a file
1 parent a0aece0 commit 8f021a2

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ Kyle Altendorf
235235
Lawrence Mitchell
236236
Lee Kamentsky
237237
Lev Maximov
238+
Levon Saldamli
238239
Lewis Cowles
239240
Llandy Riveron Del Risco
240241
Loic Esteve

changelog/11871.feature.rst

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Added support for reading ``file_or_dir`` positional arguments from a file
2+
using the prefix character '@', like e.g.:
3+
4+
``pytest @tests.txt``

src/_pytest/config/argparsing.py

+1
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ def __init__(
415415
add_help=False,
416416
formatter_class=DropShorterLongHelpFormatter,
417417
allow_abbrev=False,
418+
fromfile_prefix_chars="@",
418419
)
419420
# extra_info is a dict of (param -> value) to display if there's
420421
# an usage error to provide more contextual information to the user.

testing/test_parseopt.py

+7
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ def test_parse2(self, parser: parseopt.Parser) -> None:
125125
args = parser.parse([Path(".")])
126126
assert getattr(args, parseopt.FILE_OR_DIR)[0] == "."
127127

128+
def test_parse_from_file(self, parser: parseopt.Parser, tmp_path: Path) -> None:
129+
tests = [".", "some.py::Test::test_method[param0]", "other/test_file.py"]
130+
test_file = tmp_path / "tests.txt"
131+
test_file.write_text("\n".join(tests), encoding="utf-8")
132+
args = parser.parse([f"@{test_file.absolute()}"])
133+
assert getattr(args, parseopt.FILE_OR_DIR) == tests
134+
128135
def test_parse_known_args(self, parser: parseopt.Parser) -> None:
129136
parser.parse_known_args([Path(".")])
130137
parser.addoption("--hello", action="store_true")

0 commit comments

Comments
 (0)