allure-framework / allure-python

Allure integrations for Python test frameworks
https://allurereport.org/
Apache License 2.0
727 stars 237 forks source link

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

Open Jiff21 opened 6 years ago

Jiff21 commented 6 years ago

I'm submitting a ...

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:

PuneetSoni4 commented 4 years ago

Any update on above?

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

delatrie commented 1 year ago

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:

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:


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 commented 1 year ago

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 commented 1 year ago

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

delatrie commented 1 year ago

@Rexze001 It's not yet fixed, sorry.

Rexze001 commented 1 year ago

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