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

Allure doesn't include information appended to Scenario or Feature description in before statements #279

Open
1 task
Jiff21 opened this issue Aug 1, 2018 · 6 comments
Labels
bug Something isn't working contribute Call for a contribution theme:behave

Comments

@Jiff21
Copy link

Jiff21 commented Aug 1, 2018

I'm submitting a ...

  • [ x] bug report
  • feature request

What is the current behavior?

If you include modify a Feature or Scenario description text in Behave's before_feature or before_scenario this is not reflected in the allure result.

Steps:

I've added something like this to my environment.py file

def before_feature(context, feature):
    if 'server' in context.config.userdata:
        feature.name += ' on ' + context.config.userdata['server'] + ' environment.'

def before_scenario(context, scenario):
    if 'browser' in context.tags:
        context.driver = webdriver.Chrome()
        scenario.name += ' in ' + context.driver.capabilities['browserName'] + ' ' + context.driver.capabilities['version']

Then running with something like behave -D server="testing" qa/functional/features/

What is the expected behavior?

The feature should have on testing environment. added to it on the allure report. And the scenario should have something like in chrome 68.0.3440.84 appended to the end of the name. Currently the allure report includes the feature and scenario descriptions without the appended information. Behave will include this appended information if I do not run with the formatter.

What is the motivation / use case for changing the behavior?

I'm trying to edit the Scenario and feature names without using Tables.

Please tell us about your environment:

  • Allure version: 2.6.0
  • Test framework: behave==1.2.6
  • Allure adaptor: allure-behave==2.50
@PuneetSoni4
Copy link

PuneetSoni4 commented Sep 23, 2020

Any update on above?

@sseliverstov Could you please help with above query? Really need some feature to update the scenario name.

@delatrie delatrie added bug Something isn't working theme:behave labels Dec 5, 2022
@delatrie
Copy link
Contributor

Hi!
I was able to reproduce the issue with both a 2.5.0 and 2.12.0 (the most recent at the time) versions of allure-behave but it appeared in a slightly different way compared to the OP:

Given the following input files:

  • issue279.feature
    Feature: Reproduce issue 279
        Scenario: Scenario to reproduce issue 279
            Given Step to reproduce issue 279
  • steps.py
    from behave import given
    
    @given("Step to reproduce issue 279")
    def given_step_to_reproduce_issue_279(context):
        pass
  • environment.py
    def before_feature(context, feature):
        feature.name = "Issue 279 not reproduced for feature"
    
    def before_scenario(context, scenario):
        scenario.name = "Issue 279 not reproduced for scenario"
    
    def before_step(context, step):
        step.name = "Issue 279 not reproduced for step"

If we run the behave with the following command:

behave -f allure_behave.formatter:AllureFormatter -f pretty -o ./.allure-results/issue279 ./features/issue279.feature

Then it will produce the following results:

  • *result.json (significant fields only)
    {
        "name": "Scenario to reproduce issue 279",
        "status": "passed",
        "steps": [{
            "name": "Given Step to reproduce issue 279",
            "status": "passed"
        }],
        "labels": [{
            "name": "feature",
            "value": "Issue 279 not reproduced for feature"
        }]
    }

Looks like allure-behave picks up a name update from before_feature as expected, while ignoring one from before_scenario and before_step. I will try to fix this later.

If someone has different reproducible behavior, please, post it here.

@delatrie
Copy link
Contributor

delatrie commented Dec 19, 2022

For future contribution:

I took a look at how behave calls a formatter and environment setup functions. It is poorly documented so the best way to figure it out is to do some observations. Here is the sequence of calls I observed (being applied to allure-behave in particular):

  1. allure_behave.formatter.AllureFormatter.uri
  2. environment.before_feature
  3. allure_behave.formatter.AllureFormatter.feature
  4. allure_behave.listener.AllureListener.start_test <-- feature and scenario names are captured here
  5. environment.before_scenario
  6. allure_behave.formatter.AllureFormatter.step
  7. allure_behave.formatter.AllureFormatter.match <-- step name is captured here
  8. environment.before_step
  9. environment.after_step
  10. allure_behave.formatter.AllureFormatter.result
  11. environment.after_scenario
  12. allure_behave.listener.AllureListener.stop_test
  13. environment.after_feature
  14. allure_behave.formatter.AllureFormatter.eof
  15. allure_behave.formatter.AllureFormatter.close_stream

Given this lifecycle, it`s no surprise that the changes are not reflected properly.
To fix that we can update the test`s name, fullName and description in allure_behave.listener.AllureListener.stop_scenario, and the step`s name in allure_behave.listener.AllureListener.stop_behave_step (by providing a new name to the stop_step call).

And probably it is better to use formatter`s scenario function instead of mangling the scenario`s run function, but that requires additional testing.

@Rexze001
Copy link

Rexze001 commented Apr 25, 2023

@delatrie Hi delatrie, is this bug fixed? I meet the same question in allure-behave(version:2.13.1).

@delatrie
Copy link
Contributor

@Rexze001 It's not yet fixed, sorry.

@Rexze001
Copy link

Rexze001 commented May 4, 2023

@delatrie It's okay, hope you guys can fix it soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contribute Call for a contribution theme:behave
Projects
None yet
Development

No branches or pull requests

4 participants