diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c53a448..e4f8e3d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Fix the `--browser` flag not working on macOS [#504](https://github.com/scanapi/scanapi/pull/504) ## [2.6.0] - 2021-08-13 ### Changed diff --git a/scanapi/reporter.py b/scanapi/reporter.py index cb7eaa61..b84dfa30 100644 --- a/scanapi/reporter.py +++ b/scanapi/reporter.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 import datetime import logging +import pathlib import webbrowser -from os.path import abspath from pkg_resources import get_distribution @@ -25,7 +25,7 @@ class Reporter: def __init__(self, output_path=None, template=None): """Creates a Reporter instance object.""" - self.output_path = output_path or "scanapi-report.html" + self.output_path = pathlib.Path(output_path or "scanapi-report.html") self.template = template def write(self, results): @@ -51,11 +51,11 @@ def write(self, results): doc.write(content) logger.info("\nThe documentation was generated successfully.") - logger.info(f"It is available at {abspath(self.output_path)}") + logger.info(f"It is available at {self.output_path.resolve().as_uri()}") def open_report_in_browser(self): """Open the results file on a browser""" - webbrowser.open(self.output_path) + webbrowser.open(self.output_path.resolve().as_uri()) @staticmethod def write_without_generating_report(results): diff --git a/tests/unit/test_reporter.py b/tests/unit/test_reporter.py index f9e78fdc..adf45662 100644 --- a/tests/unit/test_reporter.py +++ b/tests/unit/test_reporter.py @@ -1,3 +1,5 @@ +import pathlib + from freezegun.api import FakeDatetime from pytest import fixture, mark @@ -20,7 +22,7 @@ class TestInit: def test_init_output_path_and_template(self): reporter = Reporter() - assert reporter.output_path == "scanapi-report.html" + assert str(reporter.output_path) == "scanapi-report.html" assert reporter.template is None @mark.context("when there is a template argument") @@ -31,7 +33,7 @@ def test_init_output_path_and_template(self): def test_init_output_path_and_template_2(self): reporter = Reporter(template="my_template.jinja") - assert reporter.output_path == "scanapi-report.html" + assert str(reporter.output_path) == "scanapi-report.html" assert reporter.template == "my_template.jinja" @mark.context("when there is an output path argument") @@ -41,7 +43,7 @@ def test_init_output_path_and_template_2(self): def test_init_output_path_and_template_3(self): reporter = Reporter(output_path="my-report.html") - assert reporter.output_path == "my-report.html" + assert str(reporter.output_path) == "my-report.html" assert reporter.template is None @@ -103,7 +105,7 @@ def test_should_write_to_default_output( mocked__render.assert_called_once_with("report.html", context, False) mocked__open.assert_called_once_with( - "scanapi-report.html", "w", newline="\n" + pathlib.Path("scanapi-report.html"), "w", newline="\n" ) mocked__open().write.assert_called_once_with("ScanAPI Report") @@ -123,7 +125,7 @@ def test_should_write_to_custom_output( mocked__render.assert_called_once_with("html", context, True) mocked__open.assert_called_once_with( - "./custom/report-output.html", "w", newline="\n" + pathlib.Path("./custom/report-output.html"), "w", newline="\n" ) mocked__open().write.assert_called_once_with("ScanAPI Report") @@ -145,7 +147,7 @@ def test_should_handle_custom_templates( "my-template.html", context, True ) mocked__open.assert_called_once_with( - "scanapi-report.html", "w", newline="\n" + pathlib.Path("scanapi-report.html"), "w", newline="\n" ) mocked__open().write.assert_called_once_with("ScanAPI Report")