From 0fca1fe7c3d35cbe57dbbdbe1cc1614cf4067a4a Mon Sep 17 00:00:00 2001 From: jenisys Date: Tue, 18 Jun 2024 21:08:57 +0200 Subject: [PATCH] PROOF-OF-CONCEPT: Adding a formatter late RELATED TO: * https://github.com/behave-contrib/behave-html-pretty-formatter/issues/72 --- issue.features/issue1181.feature | 59 ++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 issue.features/issue1181.feature diff --git a/issue.features/issue1181.feature b/issue.features/issue1181.feature new file mode 100644 index 00000000..a6270c9f --- /dev/null +++ b/issue.features/issue1181.feature @@ -0,0 +1,59 @@ +@question +Feature: Issue #1181 -- Can I add a Formatter in the before_all() Hook + + . WARNING: + . * BEWARE: This is not a valid use case. + . * Adding another formatter from the "environment.py" file is a hack + . * You should never really need to do this. + . + . SEE ALSO: + . * https://github.com/behave-contrib/behave-html-pretty-formatter/issues/72 + + + Background: + Given a new working directory + And a file named "features/steps/use_behave4cmd_steps.py" with: + """ + from __future__ import absolute_import + import behave4cmd0.passing_steps + """ + And a file named "features/environment.py" with: + """ + from __future__ import absolute_import, print_function + from behave.formatter.base import StreamOpener + from behave.formatter.progress import ScenarioStepProgressFormatter + + def before_all(ctx): + stream_opener = StreamOpener("build/report4me.txt") + new_formatter = ScenarioStepProgressFormatter(stream_opener, ctx.config) + ctx._runner.formatters.append(new_formatter) + """ + And a file named "features/example.feature" with: + """ + Feature: Example + Scenario: E1 -- Ensure that all steps pass + Given a step passes + When another step passes + Then some step passes + + Scenario: E2 -- Now every step must pass + When some step passes + Then another step passes + """ + + + Scenario: Use new Formatter from the Environment (as POC) + When I run `behave -f plain features/example.feature` + Then it should pass with: + """ + 2 scenarios passed, 0 failed, 0 skipped + 5 steps passed, 0 failed, 0 skipped, 0 undefined + """ + And a file named "build/report4me.txt" should exist + And the file "build/report4me.txt" should contain: + """ + Example # features/example.feature + E1 -- Ensure that all steps pass ... + E2 -- Now every step must pass .. + """ + And note that "the formatter from the environment could write its report"