From 698d1511c02c6fbc17d835fabab63e233abbd35e Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 8 Feb 2024 10:16:07 +0400 Subject: [PATCH 1/5] --gitlab-show-path failed passed --- setup.cfg | 2 +- setup.py | 2 +- tests/_utils.py | 2 +- tests/test_gitlab_reporter.py | 80 +++++++++++++++++++++-- vedro_gitlab_reporter/__init__.py | 2 +- vedro_gitlab_reporter/_gitlab_reporter.py | 24 +++++-- 6 files changed, 97 insertions(+), 15 deletions(-) diff --git a/setup.cfg b/setup.cfg index 428bbe1..103703f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 2.1.3 +current_version = 2.1.4 message = bump version → {new_version} commit = True tag = True diff --git a/setup.py b/setup.py index e229f58..560d436 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,7 @@ def find_dev_required(): setup( name="vedro-gitlab-reporter", - version="2.1.3", + version="2.1.4", description="GitLab reporter with collapsable sections for Vedro framework", long_description=open("README.md").read(), long_description_content_type="text/markdown", diff --git a/tests/_utils.py b/tests/_utils.py index 4ee55e8..08664e6 100644 --- a/tests/_utils.py +++ b/tests/_utils.py @@ -57,7 +57,7 @@ async def fire_arg_parsed_event(dispatcher: Dispatcher, *, GitlabReporter.tb_show_internal_calls, tb_show_locals: bool = GitlabReporter.tb_show_locals, - show_paths: bool = + show_paths: Optional[list] = GitlabReporter.show_paths) -> None: await dispatcher.fire(ConfigLoadedEvent(Path(), Config)) diff --git a/tests/test_gitlab_reporter.py b/tests/test_gitlab_reporter.py index fe3f6de..787d1ec 100644 --- a/tests/test_gitlab_reporter.py +++ b/tests/test_gitlab_reporter.py @@ -9,6 +9,7 @@ CleanupEvent, ScenarioFailedEvent, ScenarioPassedEvent, + ScenarioSkippedEvent, ScenarioReportedEvent, ScenarioRunEvent, StartupEvent, @@ -145,9 +146,9 @@ async def test_scenario_passed_with_extra_details(*, dispatcher: Dispatcher, pri @pytest.mark.usefixtures(gitlab_reporter.__name__) -async def test_scenario_passed_with_show_path(*, dispatcher: Dispatcher, printer_: Mock): +async def test_scenario_passed_with_default_show_path(*, dispatcher: Dispatcher, printer_: Mock): with given: - await fire_arg_parsed_event(dispatcher, show_paths=True) + await fire_arg_parsed_event(dispatcher) scenario_result = make_scenario_result().mark_passed() await dispatcher.fire(ScenarioPassedEvent(scenario_result)) @@ -169,6 +170,53 @@ async def test_scenario_passed_with_show_path(*, dispatcher: Dispatcher, printer ] +@pytest.mark.usefixtures(gitlab_reporter.__name__) +async def test_scenario_passed_with_none_show_path(*, dispatcher: Dispatcher, printer_: Mock): + with given: + await fire_arg_parsed_event(dispatcher, show_paths=None) + + scenario_result = make_scenario_result().mark_passed() + await dispatcher.fire(ScenarioPassedEvent(scenario_result)) + + aggregated_result = make_aggregated_result(scenario_result) + event = ScenarioReportedEvent(aggregated_result) + + with when: + await dispatcher.fire(event) + + with then: + # no printed path of scenario info + assert printer_.mock_calls == [ + call.print_scenario_subject(aggregated_result.scenario.subject, + ScenarioStatus.PASSED, + elapsed=aggregated_result.elapsed, + prefix=" "), + ] + + +@pytest.mark.usefixtures(gitlab_reporter.__name__) +async def test_scenario_passed_with_specified_show_path_not_included(*, dispatcher: Dispatcher, printer_: Mock): + with given: + await fire_arg_parsed_event(dispatcher, show_paths=[ScenarioStatus.FAILED]) + + scenario_result = make_scenario_result().mark_passed() + await dispatcher.fire(ScenarioPassedEvent(scenario_result)) + + aggregated_result = make_aggregated_result(scenario_result) + event = ScenarioReportedEvent(aggregated_result) + + with when: + await dispatcher.fire(event) + + with then: + assert printer_.mock_calls == [ + call.print_scenario_subject(aggregated_result.scenario.subject, + ScenarioStatus.PASSED, + elapsed=aggregated_result.elapsed, + prefix=" "), + ] + + @pytest.mark.usefixtures(gitlab_reporter.__name__) async def test_scenario_failed_with_extra_details(*, dispatcher: Dispatcher, printer_: Mock): with given: @@ -215,9 +263,9 @@ async def test_scenario_failed(*, dispatcher: Dispatcher, printer_: Mock): @pytest.mark.usefixtures(gitlab_reporter.__name__) -async def test_scenario_failed_with_show_paths(*, dispatcher: Dispatcher, printer_: Mock): +async def test_scenario_failed_with_default_show_paths(*, dispatcher: Dispatcher, printer_: Mock): with given: - await fire_arg_parsed_event(dispatcher, show_paths=True) + await fire_arg_parsed_event(dispatcher) scenario_result = make_scenario_result().mark_failed() await dispatcher.fire(ScenarioFailedEvent(scenario_result)) @@ -239,6 +287,30 @@ async def test_scenario_failed_with_show_paths(*, dispatcher: Dispatcher, printe ] +@pytest.mark.usefixtures(gitlab_reporter.__name__) +async def test_scenario_failed_with_none_show_paths(*, dispatcher: Dispatcher, printer_: Mock): + with given: + await fire_arg_parsed_event(dispatcher, show_paths=None) + + scenario_result = make_scenario_result().mark_failed() + await dispatcher.fire(ScenarioFailedEvent(scenario_result)) + + aggregated_result = make_aggregated_result(scenario_result) + event = ScenarioReportedEvent(aggregated_result) + + with when: + await dispatcher.fire(event) + + with then: + # no printed path of scenario info + assert printer_.mock_calls == [ + call.print_scenario_subject(aggregated_result.scenario.subject, + ScenarioStatus.FAILED, + elapsed=aggregated_result.elapsed, + prefix=" "), + ] + + @pytest.mark.usefixtures(gitlab_reporter.__name__) async def test_scenario_passed_aggregated_result(*, dispatcher: Dispatcher, printer_: Mock): with given: diff --git a/vedro_gitlab_reporter/__init__.py b/vedro_gitlab_reporter/__init__.py index 91368b1..4685457 100644 --- a/vedro_gitlab_reporter/__init__.py +++ b/vedro_gitlab_reporter/__init__.py @@ -1,5 +1,5 @@ from ._collapsable_mode import GitlabCollapsableMode from ._gitlab_reporter import GitlabReporter, GitlabReporterPlugin -__version__ = "2.1.3" +__version__ = "2.1.4" __all__ = ("GitlabReporter", "GitlabReporterPlugin", "GitlabCollapsableMode",) diff --git a/vedro_gitlab_reporter/_gitlab_reporter.py b/vedro_gitlab_reporter/_gitlab_reporter.py index 7377900..4c28ff5 100644 --- a/vedro_gitlab_reporter/_gitlab_reporter.py +++ b/vedro_gitlab_reporter/_gitlab_reporter.py @@ -17,6 +17,7 @@ StepFailedEvent, StepPassedEvent, ) +from vedro.core import ScenarioStatus from vedro.plugins.director import DirectorInitEvent, Reporter from vedro.plugins.director.rich import RichPrinter @@ -74,15 +75,24 @@ def on_arg_parse(self, event: ArgParseEvent) -> None: default=self._tb_show_locals, help="Show local variables in the traceback output") group.add_argument("--gitlab-show-paths", - action="store_true", - default=self._show_paths, - help="Show the relative path of each passed scenario") + default=None, + nargs="*", + type=str.upper, + help="Show the relative path of scenario in status (failed or passed). " + "--gitlab-show-paths - show all paths of scenarios; " + "--gitlab-show-paths=failed passed - show all paths of scenarios;" + "--gitlab-show-paths=failed - show all failed paths of scenarios;") def on_arg_parsed(self, event: ArgParsedEvent) -> None: self._collapsable_mode = event.args.gitlab_collapsable self._tb_show_internal_calls = event.args.gitlab_tb_show_internal_calls self._tb_show_locals = event.args.gitlab_tb_show_locals - self._show_paths = event.args.gitlab_show_paths + + if event.args.gitlab_show_paths == []: + # --gitlab-show-path -> gitlab_show_paths = [] -> all status + self._show_paths = [ScenarioStatus.FAILED, ScenarioStatus.PASSED] + else: + self._show_paths = event.args.gitlab_show_paths def on_startup(self, event: StartupEvent) -> None: self._printer.print_header() @@ -260,7 +270,7 @@ def _print_scope_val(self, val: Any) -> None: self._printer.print_scope_val(val) def _add_extra_details(self, scenario_result: ScenarioResult) -> None: - if self._show_paths: + if self._show_paths and scenario_result.status in self._show_paths: scenario_result.add_extra_details(f"{scenario_result.scenario.rel_path}") @@ -276,5 +286,5 @@ class GitlabReporter(PluginConfig): # Max stack trace entries to show (min=4) tb_max_frames: int = 8 - # Show the relative path of each passed scenario - show_paths: bool = False + # Show the relative path of scenario in status + show_paths: list = [ScenarioStatus.FAILED, ScenarioStatus.PASSED] From f05ca1ce9ad2c47a1db6cc34a081155333389e33 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 8 Feb 2024 12:12:11 +0400 Subject: [PATCH 2/5] fixed --- vedro_gitlab_reporter/_gitlab_reporter.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/vedro_gitlab_reporter/_gitlab_reporter.py b/vedro_gitlab_reporter/_gitlab_reporter.py index 4c28ff5..f62463b 100644 --- a/vedro_gitlab_reporter/_gitlab_reporter.py +++ b/vedro_gitlab_reporter/_gitlab_reporter.py @@ -80,19 +80,17 @@ def on_arg_parse(self, event: ArgParseEvent) -> None: type=str.upper, help="Show the relative path of scenario in status (failed or passed). " "--gitlab-show-paths - show all paths of scenarios; " - "--gitlab-show-paths=failed passed - show all paths of scenarios;" - "--gitlab-show-paths=failed - show all failed paths of scenarios;") + "--gitlab-show-paths failed passed - show all paths of scenarios;" + "--gitlab-show-paths failed - show all failed paths of scenarios;") def on_arg_parsed(self, event: ArgParsedEvent) -> None: self._collapsable_mode = event.args.gitlab_collapsable self._tb_show_internal_calls = event.args.gitlab_tb_show_internal_calls self._tb_show_locals = event.args.gitlab_tb_show_locals - if event.args.gitlab_show_paths == []: - # --gitlab-show-path -> gitlab_show_paths = [] -> all status - self._show_paths = [ScenarioStatus.FAILED, ScenarioStatus.PASSED] - else: - self._show_paths = event.args.gitlab_show_paths + # --gitlab-show-path -> default values (all) + self._show_paths = GitlabReporter.show_paths if event.args.gitlab_show_paths == [] \ + else event.args.gitlab_show_paths def on_startup(self, event: StartupEvent) -> None: self._printer.print_header() @@ -270,7 +268,7 @@ def _print_scope_val(self, val: Any) -> None: self._printer.print_scope_val(val) def _add_extra_details(self, scenario_result: ScenarioResult) -> None: - if self._show_paths and scenario_result.status in self._show_paths: + if self._show_paths and scenario_result.status.value in self._show_paths: scenario_result.add_extra_details(f"{scenario_result.scenario.rel_path}") @@ -287,4 +285,4 @@ class GitlabReporter(PluginConfig): tb_max_frames: int = 8 # Show the relative path of scenario in status - show_paths: list = [ScenarioStatus.FAILED, ScenarioStatus.PASSED] + show_paths: list = [status.value for status in [ScenarioStatus.FAILED, ScenarioStatus.PASSED]] From 04874813d57227619c7f1377efde476526640a93 Mon Sep 17 00:00:00 2001 From: anna Date: Thu, 8 Feb 2024 12:38:38 +0400 Subject: [PATCH 3/5] fixed tests --- tests/test_gitlab_reporter.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/tests/test_gitlab_reporter.py b/tests/test_gitlab_reporter.py index 787d1ec..bcdfd9d 100644 --- a/tests/test_gitlab_reporter.py +++ b/tests/test_gitlab_reporter.py @@ -9,7 +9,6 @@ CleanupEvent, ScenarioFailedEvent, ScenarioPassedEvent, - ScenarioSkippedEvent, ScenarioReportedEvent, ScenarioRunEvent, StartupEvent, @@ -194,10 +193,35 @@ async def test_scenario_passed_with_none_show_path(*, dispatcher: Dispatcher, pr ] +@pytest.mark.usefixtures(gitlab_reporter.__name__) +async def test_scenario_passed_with_specified_show_path_included(*, dispatcher: Dispatcher, printer_: Mock): + with given: + await fire_arg_parsed_event(dispatcher, show_paths=[ScenarioStatus.PASSED.value]) + + scenario_result = make_scenario_result().mark_passed() + await dispatcher.fire(ScenarioPassedEvent(scenario_result)) + + aggregated_result = make_aggregated_result(scenario_result) + event = ScenarioReportedEvent(aggregated_result) + + with when: + await dispatcher.fire(event) + + with then: + assert printer_.mock_calls == [ + call.print_scenario_subject(aggregated_result.scenario.subject, + ScenarioStatus.PASSED, + elapsed=aggregated_result.elapsed, + prefix=" "), + call.print_scenario_extra_details([f"{aggregated_result.scenario.path.name}"], + prefix=" " * 3) + ] + + @pytest.mark.usefixtures(gitlab_reporter.__name__) async def test_scenario_passed_with_specified_show_path_not_included(*, dispatcher: Dispatcher, printer_: Mock): with given: - await fire_arg_parsed_event(dispatcher, show_paths=[ScenarioStatus.FAILED]) + await fire_arg_parsed_event(dispatcher, show_paths=[ScenarioStatus.FAILED.value]) scenario_result = make_scenario_result().mark_passed() await dispatcher.fire(ScenarioPassedEvent(scenario_result)) From b2429bb84e79a9dd702c38a1e123e018f9e7f0dc Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 27 Feb 2024 10:51:09 +0400 Subject: [PATCH 4/5] edits after CR --- tests/test_gitlab_reporter.py | 8 ++++++-- vedro_gitlab_reporter/_gitlab_reporter.py | 18 ++++++++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/tests/test_gitlab_reporter.py b/tests/test_gitlab_reporter.py index bcdfd9d..d00b69b 100644 --- a/tests/test_gitlab_reporter.py +++ b/tests/test_gitlab_reporter.py @@ -194,7 +194,9 @@ async def test_scenario_passed_with_none_show_path(*, dispatcher: Dispatcher, pr @pytest.mark.usefixtures(gitlab_reporter.__name__) -async def test_scenario_passed_with_specified_show_path_included(*, dispatcher: Dispatcher, printer_: Mock): +async def test_scenario_passed_with_specified_show_path_included( + *, dispatcher: Dispatcher, printer_: Mock +): with given: await fire_arg_parsed_event(dispatcher, show_paths=[ScenarioStatus.PASSED.value]) @@ -219,7 +221,9 @@ async def test_scenario_passed_with_specified_show_path_included(*, dispatcher: @pytest.mark.usefixtures(gitlab_reporter.__name__) -async def test_scenario_passed_with_specified_show_path_not_included(*, dispatcher: Dispatcher, printer_: Mock): +async def test_scenario_passed_with_specified_show_path_not_included( + *, dispatcher: Dispatcher, printer_: Mock +): with given: await fire_arg_parsed_event(dispatcher, show_paths=[ScenarioStatus.FAILED.value]) diff --git a/vedro_gitlab_reporter/_gitlab_reporter.py b/vedro_gitlab_reporter/_gitlab_reporter.py index f62463b..18b5e4f 100644 --- a/vedro_gitlab_reporter/_gitlab_reporter.py +++ b/vedro_gitlab_reporter/_gitlab_reporter.py @@ -4,7 +4,7 @@ from typing import Any, Callable, Dict, List, Set, Type, Union import vedro -from vedro.core import Dispatcher, PluginConfig, ScenarioResult +from vedro.core import Dispatcher, PluginConfig, ScenarioResult, ScenarioStatus from vedro.events import ( ArgParsedEvent, ArgParseEvent, @@ -17,7 +17,6 @@ StepFailedEvent, StepPassedEvent, ) -from vedro.core import ScenarioStatus from vedro.plugins.director import DirectorInitEvent, Reporter from vedro.plugins.director.rich import RichPrinter @@ -35,7 +34,7 @@ def __init__(self, config: Type["GitlabReporter"], *, self._tb_show_internal_calls = config.tb_show_internal_calls self._tb_show_locals = config.tb_show_locals self._tb_max_frames = config.tb_max_frames - self._show_paths = config.show_paths + self._show_paths = config.show_paths if not False else [] self._collapsable_mode: Union[GitlabCollapsableMode, None] = None self._namespace: Union[str, None] = None @@ -78,7 +77,8 @@ def on_arg_parse(self, event: ArgParseEvent) -> None: default=None, nargs="*", type=str.upper, - help="Show the relative path of scenario in status (failed or passed). " + choices=[ScenarioStatus.FAILED.value, ScenarioStatus.PASSED.value], + help="Show the relative path of scenario in status (failed or passed)." "--gitlab-show-paths - show all paths of scenarios; " "--gitlab-show-paths failed passed - show all paths of scenarios;" "--gitlab-show-paths failed - show all failed paths of scenarios;") @@ -89,8 +89,10 @@ def on_arg_parsed(self, event: ArgParsedEvent) -> None: self._tb_show_locals = event.args.gitlab_tb_show_locals # --gitlab-show-path -> default values (all) - self._show_paths = GitlabReporter.show_paths if event.args.gitlab_show_paths == [] \ - else event.args.gitlab_show_paths + if event.args.gitlab_show_paths == []: + self._show_paths = [ScenarioStatus.FAILED, ScenarioStatus.PASSED] + elif event.args.gitlab_show_paths is not None: + self._show_paths = [ScenarioStatus(value) for value in event.args.gitlab_show_paths] def on_startup(self, event: StartupEvent) -> None: self._printer.print_header() @@ -268,7 +270,7 @@ def _print_scope_val(self, val: Any) -> None: self._printer.print_scope_val(val) def _add_extra_details(self, scenario_result: ScenarioResult) -> None: - if self._show_paths and scenario_result.status.value in self._show_paths: + if self._show_paths and scenario_result.status in self._show_paths: scenario_result.add_extra_details(f"{scenario_result.scenario.rel_path}") @@ -285,4 +287,4 @@ class GitlabReporter(PluginConfig): tb_max_frames: int = 8 # Show the relative path of scenario in status - show_paths: list = [status.value for status in [ScenarioStatus.FAILED, ScenarioStatus.PASSED]] + show_paths: list[ScenarioStatus] = [] From 69a14cc99e22fe3cb530ea236e13e314d8b3ce42 Mon Sep 17 00:00:00 2001 From: anna Date: Tue, 27 Feb 2024 19:42:15 +0400 Subject: [PATCH 5/5] fixed typing --- vedro_gitlab_reporter/_gitlab_reporter.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vedro_gitlab_reporter/_gitlab_reporter.py b/vedro_gitlab_reporter/_gitlab_reporter.py index 18b5e4f..ecc4e49 100644 --- a/vedro_gitlab_reporter/_gitlab_reporter.py +++ b/vedro_gitlab_reporter/_gitlab_reporter.py @@ -287,4 +287,4 @@ class GitlabReporter(PluginConfig): tb_max_frames: int = 8 # Show the relative path of scenario in status - show_paths: list[ScenarioStatus] = [] + show_paths: List[ScenarioStatus] = []