Skip to content

Commit c4ee71c

Browse files
committed
Fix tests on --help when invoked through 'python -m pytest'
The 'prog' value of argparse.ArgumentParser() depends on sys.argv[0]. We assumed 'pytest' in test_cli_help*.txt, but this could be 'python -m pytest' as well. Add a way to fix this value when creating the parser so that this is predictable in our tests. Fix #435.
1 parent b9e8a8f commit c4ee71c

File tree

3 files changed

+6
-5
lines changed

3 files changed

+6
-5
lines changed

pgactivity/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ def flag(p: Any, spec: str, *, dest: str, feature: str) -> None:
5656
)
5757

5858

59-
def get_parser() -> argparse.ArgumentParser:
59+
def get_parser(prog: str | None = None) -> argparse.ArgumentParser:
6060
parser = argparse.ArgumentParser(
61+
prog=prog,
6162
usage="%(prog)s [options] [connection string]",
6263
description=(
6364
"htop like application for PostgreSQL server activity monitoring."

tests/test_cli_help.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
...
66

77
>>> from pgactivity import cli
8-
>>> parser = cli.get_parser()
8+
>>> parser = cli.get_parser(prog="pg_activity")
99
>>> parser.print_help()
10-
usage: pytest [options] [connection string]
10+
usage: pg_activity [options] [connection string]
1111
<BLANKLINE>
1212
htop like application for PostgreSQL server activity monitoring.
1313
<BLANKLINE>

tests/test_cli_help_py312.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
...
66

77
>>> from pgactivity import cli
8-
>>> parser = cli.get_parser()
8+
>>> parser = cli.get_parser(prog="pg_activity")
99
>>> parser.print_help()
10-
usage: pytest [options] [connection string]
10+
usage: pg_activity [options] [connection string]
1111
<BLANKLINE>
1212
htop like application for PostgreSQL server activity monitoring.
1313
<BLANKLINE>

0 commit comments

Comments
 (0)