Skip to content

Commit

Permalink
support custom statuses for --show-paths (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
mytestopia authored Feb 27, 2024
1 parent 04a4696 commit 647db7a
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 2.1.3
current_version = 2.1.4
message = bump version → {new_version}
commit = True
tag = True
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tests/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
108 changes: 104 additions & 4 deletions tests/test_gitlab_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,60 @@ 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))

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_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_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))
Expand All @@ -169,6 +220,31 @@ async def test_scenario_passed_with_show_path(*, dispatcher: Dispatcher, printer
]


@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.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=" "),
]


@pytest.mark.usefixtures(gitlab_reporter.__name__)
async def test_scenario_failed_with_extra_details(*, dispatcher: Dispatcher, printer_: Mock):
with given:
Expand Down Expand Up @@ -215,9 +291,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))
Expand All @@ -239,6 +315,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:
Expand Down
2 changes: 1 addition & 1 deletion vedro_gitlab_reporter/__init__.py
Original file line number Diff line number Diff line change
@@ -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",)
28 changes: 19 additions & 9 deletions vedro_gitlab_reporter/_gitlab_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -34,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
Expand Down Expand Up @@ -74,15 +74,25 @@ 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,
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;")

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

# --gitlab-show-path -> default values (all)
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()
Expand Down Expand Up @@ -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}")


Expand All @@ -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] = []

0 comments on commit 647db7a

Please sign in to comment.