Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add parameter '--show-paths' #6

Merged
merged 1 commit into from
Jan 10, 2024
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
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.2
current_version = 2.1.3
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.2",
version="2.1.3",
description="GitLab reporter with collapsable sections for Vedro framework",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
Expand Down
7 changes: 5 additions & 2 deletions tests/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,18 @@ async def fire_arg_parsed_event(dispatcher: Dispatcher, *,
tb_show_internal_calls: bool =
GitlabReporter.tb_show_internal_calls,
tb_show_locals: bool =
GitlabReporter.tb_show_locals) -> None:
GitlabReporter.tb_show_locals,
show_paths: bool =
GitlabReporter.show_paths) -> None:
await dispatcher.fire(ConfigLoadedEvent(Path(), Config))

arg_parse_event = ArgParseEvent(ArgumentParser())
await dispatcher.fire(arg_parse_event)

namespace = Namespace(gitlab_collapsable=collapsable_mode,
gitlab_tb_show_internal_calls=tb_show_internal_calls,
gitlab_tb_show_locals=tb_show_locals)
gitlab_tb_show_locals=tb_show_locals,
gitlab_show_paths=show_paths)
arg_parsed_event = ArgParsedEvent(namespace)
await dispatcher.fire(arg_parsed_event)

Expand Down
59 changes: 58 additions & 1 deletion tests/test_gitlab_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@
from vedro.core import AggregatedResult, Dispatcher
from vedro.core import MonotonicScenarioScheduler as ScenarioScheduler
from vedro.core import Report, ScenarioStatus
from vedro.events import CleanupEvent, ScenarioReportedEvent, ScenarioRunEvent, StartupEvent
from vedro.events import (
CleanupEvent,
ScenarioFailedEvent,
ScenarioPassedEvent,
ScenarioReportedEvent,
ScenarioRunEvent,
StartupEvent,
)
from vedro.plugins.director import DirectorInitEvent, DirectorPlugin

from vedro_gitlab_reporter import GitlabReporter, GitlabReporterPlugin
Expand Down Expand Up @@ -137,6 +144,31 @@ 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):
with given:
await fire_arg_parsed_event(dispatcher, show_paths=True)

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_failed_with_extra_details(*, dispatcher: Dispatcher, printer_: Mock):
with given:
Expand Down Expand Up @@ -182,6 +214,31 @@ 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):
with given:
await fire_arg_parsed_event(dispatcher, show_paths=True)

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:
assert printer_.mock_calls == [
call.print_scenario_subject(aggregated_result.scenario.subject,
ScenarioStatus.FAILED,
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_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.2"
__version__ = "2.1.3"
__all__ = ("GitlabReporter", "GitlabReporterPlugin", "GitlabCollapsableMode",)
20 changes: 20 additions & 0 deletions vedro_gitlab_reporter/_gitlab_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
ArgParsedEvent,
ArgParseEvent,
CleanupEvent,
ScenarioFailedEvent,
ScenarioPassedEvent,
ScenarioReportedEvent,
ScenarioRunEvent,
StartupEvent,
Expand All @@ -32,6 +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._collapsable_mode: Union[GitlabCollapsableMode, None] = None

self._namespace: Union[str, None] = None
Expand All @@ -48,6 +51,8 @@ def on_chosen(self) -> None:
.listen(ArgParsedEvent, self.on_arg_parsed) \
.listen(StartupEvent, self.on_startup) \
.listen(ScenarioRunEvent, self.on_scenario_run) \
.listen(ScenarioPassedEvent, self.on_scenario_end) \
.listen(ScenarioFailedEvent, self.on_scenario_end) \
.listen(StepPassedEvent, self.on_step_end) \
.listen(StepFailedEvent, self.on_step_end) \
.listen(ScenarioReportedEvent, self.on_scenario_reported) \
Expand All @@ -68,11 +73,16 @@ def on_arg_parse(self, event: ArgParseEvent) -> None:
action="store_true",
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")

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

def on_startup(self, event: StartupEvent) -> None:
self._printer.print_header()
Expand All @@ -89,6 +99,9 @@ def on_scenario_run(self, event: ScenarioRunEvent) -> None:
self._scenario_steps.append({})
self._scenario_result = event.scenario_result

def on_scenario_end(self, event: Union[ScenarioPassedEvent, ScenarioFailedEvent]) -> None:
self._add_extra_details(event.scenario_result)

def on_step_end(self, event: Union[StepPassedEvent, StepFailedEvent]) -> None:
assert isinstance(self._scenario_result, ScenarioResult)

Expand Down Expand Up @@ -246,6 +259,10 @@ def _print_scope_val(self, val: Any) -> None:
else:
self._printer.print_scope_val(val)

def _add_extra_details(self, scenario_result: ScenarioResult) -> None:
if self._show_paths:
scenario_result.add_extra_details(f"{scenario_result.scenario.rel_path}")


class GitlabReporter(PluginConfig):
plugin = GitlabReporterPlugin
Expand All @@ -258,3 +275,6 @@ 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