Skip to content

Commit 90366ee

Browse files
authored
Fix basilisp test CLI command to pass remaining args to PyTest (#1127)
Fixes #1119 @ikappaki I think this change will work now. I tried it on 3.11.7, 3.12.7, and 3.13.0 using the [repository](https://github.com/ikappaki/issue-bastest) and makefile you prepared to test and each worked as expected.
1 parent fb28054 commit 90366ee

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

src/basilisp/cli.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,10 @@ def test(
734734
) -> None: # pragma: no cover
735735
init_path(args)
736736
basilisp.init(_compiler_opts(args))
737+
# parse_known_args leaves the `--` separator as the first element if it is present
738+
# but retaining that causes PyTest to interpret all the arguments as positional
739+
if extra and extra[0] == "--":
740+
extra = extra[1:]
737741
try:
738742
import pytest
739743
except (ImportError, ModuleNotFoundError):
@@ -747,14 +751,29 @@ def test(
747751
@_subcommand(
748752
"test",
749753
help="run tests in a Basilisp project",
750-
description="Run tests in a Basilisp project.",
754+
description=textwrap.dedent(
755+
"""Run tests in a Basilisp project.
756+
757+
Any options not recognized by Basilisp and all positional arguments will
758+
be collected and passed on to PyTest. It is possible to directly signal
759+
the end of option processing using an explicit `--` as in:
760+
761+
`basilisp test -p other_dir -- -k vector`
762+
763+
This can be useful to also directly execute PyTest commands with Basilisp.
764+
For instance, you can directly print the PyTest command-line help text using:
765+
766+
`basilisp test -- -h`
767+
768+
If all options are unambiguous (e.g. they are only either used by Basilisp
769+
or by PyTest), then you can omit the `--`:
770+
771+
`basilisp test -k vector -p other_dir`"""
772+
),
751773
handler=test,
752774
allows_extra=True,
753775
)
754776
def _add_test_subcommand(parser: argparse.ArgumentParser) -> None:
755-
parser.add_argument(
756-
"args", nargs=argparse.REMAINDER, help="arguments passed on to Pytest"
757-
)
758777
_add_compiler_arg_group(parser)
759778
_add_import_arg_group(parser)
760779
_add_runtime_arg_group(parser)

0 commit comments

Comments
 (0)