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

Show paths custom #7

Merged
merged 5 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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.3
current_version = 2.1.4
tsv1 marked this conversation as resolved.
Show resolved Hide resolved
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
104 changes: 100 additions & 4 deletions tests/test_gitlab_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,58 @@ 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 +218,29 @@ 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 +287,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 +311,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",)
22 changes: 15 additions & 7 deletions vedro_gitlab_reporter/_gitlab_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -74,15 +75,22 @@ 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,
tsv1 marked this conversation as resolved.
Show resolved Hide resolved
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)
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()
Expand Down Expand Up @@ -260,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:
if self._show_paths and scenario_result.status.value in self._show_paths:
scenario_result.add_extra_details(f"{scenario_result.scenario.rel_path}")


Expand All @@ -276,5 +284,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 = [status.value for status in [ScenarioStatus.FAILED, ScenarioStatus.PASSED]]
tsv1 marked this conversation as resolved.
Show resolved Hide resolved
Loading