allure-framework / allure-python

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

pytest-bdd: attachments are cloned in the step and in the test #474

Closed nyermolenko-eis closed 1 year ago

nyermolenko-eis commented 4 years ago

image

Attachment is set up in the scope of the method only (but it's a fixture)' image

delatrie commented 1 year ago

Hi, @nyermolenko-eis !

If you need to pass the result of a step into another step, use target_fixture instead:

@when("user calls GetQuery API endpoint", target_fixture="api_response")
def api_response():
    response = ...
    allure.attach("Text", "attachment-1", AttachmentType.TEXT)
    return response

@then("response is ok")
def validate_response(api_response):
    ...

Otherwise, it is expected for a fixture to be called before each test function where it is required, applying all the associated side effects during each call. Trying to revert those side effects (allure.attach is just one of them) is clearly a dead-end to me.

I will hold this issue opened for a week or two. If you cannot use target_fixture for some reason, please, provide more details about your scenario. Otherwise, you can close the issue and the pull request by yourself (or I will close them later if no feedback is given).