Attachments doesnt works with pre-test fixtures
@pytest.fixture(autouse=True, scope='session')
def configuration(config):
attach_json_to_report("Config", config)
test\conftest.py:27:
test\commons\utils\reporting_utils.py:9: in attach_json_to_report allure.attach(name=name, body=json, attachment_type=allure.attachment_type.JSON) .venv\lib\site-packages\allure_commons_allure.py:164: in call plugin_manager.hook.attach_data(body=body, name=name, attachment_type=attachment_type, extension=extension) .venv\lib\site-packages\allure_pytest_bdd\pytest_bdd_listener.py:118: in attach_data self.lifecycle.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension) .venv\lib\site-packages\allure_commons\lifecycle.py:146: in attach_data file_name = self._attach(uuid, name=name, attachment_type=attachment_type, extension=extension)
self = <allure_commons.lifecycle.AllureLifecycle object at 0x038F8130>, uuid = None, name = 'Config', attachment_type = <AttachmentType.JSON: ('application/json', 'json')>, extension = 'json'
def _attach(self, uuid, name=None, attachment_type=None, extension=None):
mime_type = attachment_type
extension = extension if extension else 'attach'
if type(attachment_type) is AttachmentType:
extension = attachment_type.extension
mime_type = attachment_type.mime_type
file_name = ATTACHMENT_PATTERN.format(prefix=uuid, ext=extension)
attachment = Attachment(source=file_name, name=name, type=mime_type)
uuid = self._last_item_uuid(item_type=ExecutableItem)
self._items[uuid].attachments.append(attachment)
E KeyError: None
.venv\lib\site-packages\allure_commons\lifecycle.py:137: KeyError
Reproducible even with function-scoped fixture.
Steps to reproduce
- Given
issue475.feature:Feature: Issue 475 investigation Scenario: Reproducing the issue 475 - And
issue475_test.py:import allure import pytest from allure_commons.types import AttachmentType from pytest_bdd import scenario @pytest.fixture() def fixture(): allure.attach("Content", "traceback", AttachmentType.TEXT) yield @scenario("issue475.feature", "Reproducing the issue 475") def test_reproduction(fixture): pass - When we execute pytest:
pytest --alluredir=allure-results issue475_test.py - Then the following error happens:
___________________________________ ERROR at setup of test_reproduction ____________________________________ @pytest.fixture() def fixture(): > allure.attach("Content", "traceback", AttachmentType.TEXT) issue475_test.py:8: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ .venv/python-bug-reproduction/lib/python3.11/site-packages/allure_commons/_allure.py:200: in __call__ plugin_manager.hook.attach_data(body=body, name=name, attachment_type=attachment_type, extension=extension) .venv/python-bug-reproduction/lib/python3.11/site-packages/allure_pytest_bdd/pytest_bdd_listener.py:123: in attach_data self.lifecycle.attach_data(uuid4(), body, name=name, attachment_type=attachment_type, extension=extension) .venv/python-bug-reproduction/lib/python3.11/site-packages/allure_commons/lifecycle.py:147: in attach_data file_name = self._attach(uuid, name=name, attachment_type=attachment_type, _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <allure_commons.lifecycle.AllureLifecycle object at 0x7ff9a770ca10> uuid = '3b205b28-3afb-4dc3-bcb2-4a0b173130cc', name = 'traceback' attachment_type = <AttachmentType.TEXT: ('text/plain', 'txt')>, extension = 'txt', parent_uuid = None def _attach(self, uuid, name=None, attachment_type=None, extension=None, parent_uuid=None): mime_type = attachment_type extension = extension if extension else 'attach' if type(attachment_type) is AttachmentType: extension = attachment_type.extension mime_type = attachment_type.mime_type file_name = ATTACHMENT_PATTERN.format(prefix=uuid, ext=extension) attachment = Attachment(source=file_name, name=name, type=mime_type) last_uuid = parent_uuid if parent_uuid else self._last_item_uuid(ExecutableItem) > self._items[last_uuid].attachments.append(attachment) E KeyError: None .venv/python-bug-reproduction/lib/python3.11/site-packages/allure_commons/lifecycle.py:137: KeyError