diff --git a/CHANGELOG.md b/CHANGELOG.md index e2b6fcb4..86da428d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project closely adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.205.0 +- change - increase information logged for failing before_scenario_hooks + ## 0.204.0 - chore - add gh workflows for publishing - chore - fix project metadata diff --git a/features/cli/run_with_hooks.feature b/features/cli/run_with_hooks.feature index 557e8987..4ff5db73 100644 --- a/features/cli/run_with_hooks.feature +++ b/features/cli/run_with_hooks.feature @@ -56,6 +56,7 @@ Feature: Run with hooks .* DEBUG just logging some stuff from my before all hook Feature: Feature that simply echo's "Hello World" .* DEBUG just logging some stuff from my before scenario hook + .* DEBUG HOOK before_scenario_log: passed ✅ Scenario: This is a scenario that simply echo's hello world .* DEBUG just logging some stuff from my before step hook @@ -203,7 +204,7 @@ Feature: Run with hooks When I run the command "cucu run {CUCU_RESULTS_DIR}/failing_before_hooks/echo.feature --results {CUCU_RESULTS_DIR}/failing_before_hooks_results/ --generate-report --report {CUCU_RESULTS_DIR}/failing_before_hooks_report/" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "1" Then I should see "{STDOUT}" contains the following """ - HOOK-ERROR in before_scenario: RuntimeError: boom + HOOK-ERROR in before_scenario_fail: RuntimeError: boom """ And I should see "{STDOUT}" contains the following """ @@ -303,3 +304,40 @@ Feature: Run with hooks And I click the link "Feature that has failing and passing after scenario hooks" And I click the link "Hello world scenario" Then I should see the text "Hello World" + + @QE-16733 + Scenario: When a before_scenario hook fails, the Scenario is skipped, but reports as errored + Given I create a file at "{CUCU_RESULTS_DIR}/custom_hooks/environment.py" with the following: + """ + from cucu.environment import * + from cucu import register_before_scenario_hook + + def before_scenario_error(ctx): + raise RuntimeError("This error should be logged and reported.") + + register_before_scenario_hook(before_scenario_error) + """ + And I create a file at "{CUCU_RESULTS_DIR}/custom_hooks/steps/__init__.py" with the following: + """ + from cucu.steps import * + """ + And I create a file at "{CUCU_RESULTS_DIR}/custom_hooks/echo.feature" with the following: + """ + Feature: Feature that simply echoes "Hello World" + + Scenario: This is a scenario that simply echoes hello world + Given I echo "Hello" + And I echo "World" + """ + * # The --show-skips argument is necessary for both the `cucu run` command and the `cucu report` command + When I run the command "cucu run {CUCU_RESULTS_DIR}/custom_hooks/echo.feature --show-skips --results {CUCU_RESULTS_DIR}/custom_hooks_results/ -l debug --no-color-output" and save stdout to "STDOUT", stderr to "STDERR" and expect exit code "1" + When I run the command "cucu report {CUCU_RESULTS_DIR}/custom_hooks_results --show-skips --output {CUCU_RESULTS_DIR}/browser-report" and expect exit code "0" + And I start a webserver at directory "{CUCU_RESULTS_DIR}/browser-report/" and save the port to the variable "PORT" + And I open a browser at the url "http://{HOST_ADDRESS}:{PORT}/flat.html" + Then I should see a table that contains rows matching the following + | .* | Feature that simply echoes "Hello World" | This is a scenario that simply echoes hello world | .* | errored | .* | + And I wait to click the link "This is a scenario that simply echoes hello world" + * # Additional check of the log file itself here, when QE-16733 is resolved + # When I wait to click the link "Logs" + # And I wait to click the link "cucu.debug.console.log" + # Then I wait to see the text "This error should be logged and reported." diff --git a/pyproject.toml b/pyproject.toml index a7e83a0a..01929339 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "cucu" -version = "0.204.0" +version = "0.205.0" description = "Easy BDD web testing" readme = "README.md" license = "The Clear BSD License" diff --git a/src/cucu/environment.py b/src/cucu/environment.py index a4b532fc..97bb29c4 100644 --- a/src/cucu/environment.py +++ b/src/cucu/environment.py @@ -128,7 +128,19 @@ def before_scenario(ctx, scenario): # run before all scenario hooks for hook in CONFIG["__CUCU_BEFORE_SCENARIO_HOOKS"]: - hook(ctx) + try: + hook(ctx) + logger.debug(f"HOOK {hook.__name__}: passed ✅") + except Exception as e: + error_message = ( + f"HOOK-ERROR in {hook.__name__}: {e.__class__.__name__}: {e}\n" + ) + error_message += traceback.format_exc() + logger.error(error_message) + ctx.scenario.mark_skipped() + # Set 'hook_failed' status to 'True' so that the test gets marked + # as 'errored', even though no steps ran + ctx.scenario.hook_failed = True def run_after_scenario_hook(ctx, scenario, hook): @@ -136,7 +148,8 @@ def run_after_scenario_hook(ctx, scenario, hook): hook(ctx) logger.debug(f"HOOK {hook.__name__}: passed ✅") except Exception as e: - # For any after scenario hooks,'hook_failed' status will be 'False' but will attach the error message to scenario. + # For any after scenario hooks,'hook_failed' status will be 'False' + # but will attach the error message to scenario. error_message = ( f"HOOK-ERROR in {hook.__name__}: {e.__class__.__name__}: {e}\n" ) diff --git a/src/cucu/reporter/html.py b/src/cucu/reporter/html.py index 0c2beb67..6aaa51f4 100644 --- a/src/cucu/reporter/html.py +++ b/src/cucu/reporter/html.py @@ -283,7 +283,7 @@ def generate(results, basepath, only_failures=False): f"{scenario_filepath}/" ) - if ".console." in log_filepath: + if ".console." in log_filepath and scenario_started_at: log_filepath += ".html" log_files.append(