Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ pgpro-pytest-html-merger -i ./unit-tests -i ./e2e-tests extra-report.html -o ful

| Argument | Shorthand | Description | Default |
| :--- | :--- | :--- | :--- |
| `--version` | | Show program's version number and exit | None |
| `--input-dir` | `-i` | Directory containing HTML reports (can be used multiple times) | None |
| `--out` | `-o` | Name of the output HTML report | `merged.html` |
| `--title` | `-t` | Title of the output HTML report | None |
Expand Down
15 changes: 12 additions & 3 deletions src/pgpro_pytest_html_merger/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from packaging.version import Version

from . import __version__ as current_version

log = logging.getLogger(__name__)


Expand All @@ -23,6 +25,13 @@ def parse_arguments():
epilog="Example: pgpro-pytest-html-merger -i ./reports -o summary.html --title 'Nightly Build'", # noqa: E501
)

command_parser.add_argument(
"--version",
action="version",
version=f"%(prog)s {current_version}",
help="Show program's version number and exit",
)

command_parser.add_argument(
"--out",
"-o",
Expand Down Expand Up @@ -591,10 +600,10 @@ def _process_test(self, test: typing.Dict[str, typing.Any]) -> None:
def process_report(self, report_path):
self._report_count += 1

html_doc = ""
with open(report_path, "r") as f:
html_doc = f.read()
soup = bs4.BeautifulSoup(html_doc, features="html.parser")
soup = bs4.BeautifulSoup(f, features="html.parser")

assert isinstance(soup, bs4.BeautifulSoup)

html_version = __class__._extract_pytest_html_version(
report_path,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/e2eworkspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def generate_report(
f"but failed to generate report at: {report_path}"
)

return report_path
return str(report_path)

def run_merger(self, args: list):
env = os.environ.copy()
Expand Down
20 changes: 19 additions & 1 deletion tests/integration/test_set001__cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import subprocess
import os
import typing
import sys
import re

from src.pgpro_pytest_html_merger import __version__ as prog_version

# //////////////////////////////////////////////////////////////////////////////

Expand All @@ -14,7 +18,7 @@ def run_cli(args: typing.List[str]) -> subprocess.CompletedProcess:
env["PYTHONPATH"] = "src" + os.pathsep + env.get("PYTHONPATH", "")

return subprocess.run(
["python3", "-m", "pgpro_pytest_html_merger"] + args,
[sys.executable, "-m", "pgpro_pytest_html_merger"] + args,
capture_output=True,
text=True,
env=env,
Expand Down Expand Up @@ -69,6 +73,7 @@ def test_cli_help():
assert "merge multiple pytest-html reports" in output
assert "--input-dir" in output
assert "--out" in output
assert "--version" in output
return


Expand Down Expand Up @@ -160,4 +165,17 @@ def test_cli_error_on_duplicate_files(tmp_path):
return


# ------------------------------------------------------------------------
def test_cli_version():
"""
Check that --version prints the version and exits with code 0.
"""
result = run_cli(["--version"])

assert result.returncode == 0
# We check that the output contains the version of our utility.
assert re.search(re.escape(" " + prog_version) + "$", result.stdout) is not None
return


# //////////////////////////////////////////////////////////////////////////////