Skip to content
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
9 changes: 9 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
behave-html-pretty-formatter 1.15
=================================
Fix behave version to 1.3.0.
Fix before scenario step handling (new behave calls methods in reverse).
Add default background to unhandled scenario status.
Support late registration of formatter in before_scenario
Fix dependency on external tools in tests


behave-html-pretty-formatter 1.14.2
===================================
Respect encoding inherited from behave.
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def step_the_command_returncode_is_nonzero(context):
@then("it should pass")
def step_it_should_pass(context):
assert_that(
context.command_result.returncode, equal_to(0), context.command_result.output
context.command_result.returncode, equal_to(0), context.command_result.output,
)


Expand All @@ -222,7 +222,7 @@ def step_it_should_pass_with(context):
assert context.text is not None, "ENSURE: multiline text is provided."
step_command_output_should_contain(context)
assert_that(
context.command_result.returncode, equal_to(0), context.command_result.output
context.command_result.returncode, equal_to(0), context.command_result.output,
)


Expand Down Expand Up @@ -298,7 +298,7 @@ def step_command_output_should_contain_text_multiple_times(context, text, count)
actual_output = context.command_result.output
with on_assert_failed_print_details(actual_output, expected_text):
textutil.assert_normtext_should_contain_multiple_times(
actual_output, expected_text, count
actual_output, expected_text, count,
)


Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions behave_html_pretty_formatter/behave.css
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ pre * {
margin-top: 0;
margin-bottom: 0;
color: var(--strong-color);
background: var(--feature-bg);
}

.scenario-capsule:last-child {
Expand Down
2 changes: 1 addition & 1 deletion behave_html_pretty_formatter/behave.min.css

Large diffs are not rendered by default.

24 changes: 13 additions & 11 deletions behave_html_pretty_formatter/html_pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def __init__(self, feature, feature_counter):
self.scenario_finished = True
self.scenario_begin_timestamp = time.time()
self.before_scenario_duration = 0.0
self.before_scenario_status = Status.skipped

def add_background(self, background):
"""
Expand All @@ -104,7 +103,6 @@ def add_scenario(self, scenario, scenario_counter, pseudo_steps=False):
"""
Create new scenario in feature based on behave scenario object
"""

# React to fail in before_scenario, do not fail on no 'run' in scenario.
if not hasattr(scenario, "run"):
self._scenario_run_id = 0
Expand All @@ -121,13 +119,8 @@ def add_scenario(self, scenario, scenario_counter, pseudo_steps=False):
for embed_data in self.to_embed:
_scenario.embed(embed_data)
self.to_embed = []
# Stop embedding to before_scenario.
_scenario.pseudo_step_id = 1

if pseudo_steps:
_step = _scenario.before_scenario_step
_step.duration = self.before_scenario_duration
_step.status = self.before_scenario_status
# embed to before_scenario, since behave==1.3.0 the order of calls is reversed: add_scenario(), before_scenario_finish()
_scenario.pseudo_step_id = 0

self.scenarios.append(_scenario)
return _scenario
Expand All @@ -146,7 +139,12 @@ def before_scenario_finish(self, status):
Sets status and duration of before scenario pseudo step.
"""
self.before_scenario_duration = time.time() - self.scenario_begin_timestamp
self.before_scenario_status = Status.from_name(status)
_scenario = self.scenarios[-1]
_scenario.pseudo_step_id = 1
_step = _scenario.before_scenario_step
if _step is not None:
_step.duration = self.before_scenario_duration
_step.status = Status.from_name(status)

def after_scenario_finish(self, status):
"""
Expand Down Expand Up @@ -1157,7 +1155,7 @@ class PrettyHTMLFormatter(Formatter):
feature_counter = 0
scenario_counter = 0

def __init__(self, stream, config):
def __init__(self, stream, config, _late_registration_feature=None):
super().__init__(stream, config)

self.features = []
Expand Down Expand Up @@ -1249,6 +1247,10 @@ def __init__(self, stream, config):
short_key = key.replace(additional_info_path, "")
self.additional_info[short_key] = item

# In case of custom registration in before_scenario.
if _late_registration_feature:
self.feature(_late_registration_feature)

atexit.register(self._force_close)

def get_collapse_cls(self, item_type):
Expand Down
123 changes: 62 additions & 61 deletions docs/index.html

Large diffs are not rendered by default.

13 changes: 6 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "behave-html-pretty-formatter"
version = "1.14.2"
version = "1.15"
description = "Pretty HTML Formatter for Behave"
readme = "README.md"
license = {file = "LICENSE"}
Expand Down Expand Up @@ -42,7 +42,7 @@ keywords = [
]
requires-python = ">=3.6"
dependencies = [
"behave==1.2.6",
"behave>=1.3.0",
"dominate==2.9.0",
"markdown",
]
Expand Down Expand Up @@ -101,15 +101,14 @@ color = false
extend-exclude = "behave4cmd0"

[tool.ruff]
extend-exclude = ["tests/acceptance/steps/behave4cmd0"]
extend-exclude = ["behave4cmd0"]
extend-select = ["B", "BLE", "C4", "C90", "COM", "DJ", "DTZ", "EM", "G", "I", "N", "PIE", "PL", "PT", "PTH", "R", "S", "SIM", "T10", "TID", "W", "YTT"]
extend-ignore = []

[tool.ruff.per-file-ignores]
[tool.ruff.lint.per-file-ignores]
"behave_html_pretty_formatter/__init__.py" = ["F401"]
"behave_html_pretty_formatter/html_pretty.py" = ["DTZ005", "PLR0913", "SIM102", "SIM117", "C901"]
"tests/**/*.py" = ["S101"]
"tests/acceptance/steps/*.py" = ["F821"]

"tests/acceptance/steps/*.py" = ["F821", "S101"]
"tests/formatter_features/features/steps/*.py" = ["F821", "S101"]
[tool.setuptools.packages.find]
namespaces = false
7 changes: 4 additions & 3 deletions tests/acceptance/features/help-screen.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,17 @@ Feature: List HTML formatter among the available formatters
So that I can verify I have integrated it correctly.

Scenario: List available formatters
Given a file named "behave.ini" with:
Given a file named "behave.ini" with
"""
[behave.formatters]
html-pretty = behave_html_pretty_formatter:PrettyHTMLFormatter
"""
When I run "behave --format help"
Then it should pass
And the command output should contain:
And the command output should contain
"""
Available formatters:
AVAILABLE FORMATTERS:
captured Inspect captured output.
html-pretty Pretty HTML Formatter
json JSON dump of test run
"""
27 changes: 19 additions & 8 deletions tests/acceptance/features/html-output.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,53 @@ Feature: Make behave generate Pretty HTML as output
So that I can ensure integration and basic functionality.

Scenario: Run behave with Pretty HTML Formatter
Given a file named "behave.ini" with:
Given a file named "behave.ini" with
"""
[behave.formatters]
html-pretty = behave_html_pretty_formatter:PrettyHTMLFormatter
"""
And a file named "features/steps/use_behave4cmd0_steps.py" with
"""
from behave4cmd0 import passing_steps
"""
And a file named "features/passing.feature" with
"""
Feature: Passing
Scenario: One
Given a step passes
When another step passes
"""
When I run "behave --format html-pretty --dry-run"
Then it should pass
And the command output should contain:
And the command output should contain
"""
<!DOCTYPE html>
<html>
"""
And the command output should contain:
And the command output should contain
"""
<head>
<title>Test Suite Reporter</title>
"""
And the command output should contain:
And the command output should contain
"""
<meta content="text/html;charset=utf-8" http-equiv="content-type">
"""
And the command output should contain:
And the command output should contain
"""
<style rel="stylesheet">
"""
And the command output should contain:
And the command output should contain
"""
<script type="text/javascript">
"""
And the command output should contain:
And the command output should contain
"""
</script>
</head>
<body onload="body_onload();">
"""
And the command output should contain:
And the command output should contain
"""
</body>
</html>
Expand Down
8 changes: 7 additions & 1 deletion tests/formatter_features/behave.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# -- FILE: behave.ini
# Define ALIAS for PrettyHTMLFormatter.
[behave]
default_format = pretty
# -- ENSURE: At least one html-pretty formatter is used.
format = html-pretty
output = report.html

[behave.formatters]
html-pretty = behave_html_pretty_formatter:PrettyHTMLFormatter

Expand All @@ -8,7 +14,7 @@ html-pretty = behave_html_pretty_formatter:PrettyHTMLFormatter
[behave.userdata]
behave.formatter.html-pretty.title_string = Dummy Test Suite
# Example use case, print {before/after}_scenarios as steps with attached data.
behave.formatter.html-pretty.pseudo_steps = false
behave.formatter.html-pretty.pseudo_steps = true
# Structure of the result html page readable(pretty) or condensed.
behave.formatter.html-pretty.pretty_output = true
# The '%' must be escaped in ini format.
Expand Down
20 changes: 6 additions & 14 deletions tests/formatter_features/features/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import sys
import traceback

from qecore.sandbox import TestSandbox


def before_all(context) -> None:
"""
Expand All @@ -20,20 +18,12 @@ def before_all(context) -> None:

try:

context.sandbox = TestSandbox("dummy", context=context)

# Adds only noise to this example, turning it off.
context.sandbox.status_report = False
context.sandbox.change_title = False

context.dummy = context.sandbox.get_application(
name="dummy",
desktop_file_exists=False,
)
# ... various other actions ...

for formatter in context._runner.formatters:
if formatter.name == "html-pretty":
context.html_formatter = formatter
context.embed = context.html_formatter.embed

except Exception as error:
print(f"Environment error: before_all: {error}")
Expand All @@ -49,7 +39,8 @@ def before_scenario(context, scenario) -> None:
"""

try:
context.sandbox.before_scenario(context, scenario)

# ... various other actions ...

if "dummy_scenario_pass_pseudo_steps" in scenario.effective_tags:
context.html_formatter.pseudo_steps = True
Expand Down Expand Up @@ -80,7 +71,8 @@ def after_scenario(context, scenario) -> None:
"""

try:
context.sandbox.after_scenario(context, scenario)

# ... various other actions ...

if "dummy_scenario_pass_pseudo_steps" in scenario.effective_tags:

Expand Down
13 changes: 6 additions & 7 deletions tests/formatter_features/features/scenarios/00_dummy.feature
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
@dummy_feature
Feature: Dummy Feature


@dummy_scenario_pass
Scenario: Dummy Scenario Pass
@dummy_scenario_pass_pseudo_steps
Scenario: Dummy Scenario Pass Pseudo Steps
* Dummy pass


@dummy_scenario_pass_pseudo_steps
Scenario: Dummy Scenario Pass Pseudo Steps
@dummy_scenario_pass
Scenario: Dummy Scenario Pass
* Dummy pass


Expand Down Expand Up @@ -37,15 +36,15 @@ Feature: Dummy Feature
@dummy_scenario_table_and_text
Scenario: Dummy Scenario Table and Text
* Dummy pass
* Table Example:
* Table Example
| Field | Data |
| Number | dummy_data |
| Number_1 | dummy_data_1 |
| Number_2 | dummy_data_2 |
| Number_3 | dummy_data_3 |
| Number_3 | dummy_data_4 |
* Dummy pass
* Text Example:
* Text Example
"""
Hello World
Hello World Again
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ envlist =
[testenv]
description = Tests
deps =
behave==1.2.6
behave>=1.3.0
PyHamcrest
commands =
behave {posargs: tests/acceptance/}
Expand Down
Loading