Allure attachment fails in after_all() method of python-behave framework
I'm submitting a ...
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
What is the current behavior?
printed error: HOOK-ERROR in after_all: KeyError: None
Actual error raised:
Exception has occurred: KeyError
None
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/allure_commons/reporter.py", line 33, in __getitem__
return self.thread_context.__getitem__(item)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/allure_commons/reporter.py", line 153, in _attach
self._items[last_uuid].attachments.append(attachment)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/allure_commons/reporter.py", line 158, in attach_file
file_name = self._attach(uuid, name=name, attachment_type=attachment_type,
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/allure_behave/listener.py", line 174, in attach_file
self.logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/pluggy/_callers.py", line 77, in _multicall
res = hook_impl.function(*args)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/pluggy/_manager.py", line 115, in _hookexec
return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/pluggy/_hooks.py", line 493, in __call__
return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/allure_commons/_allure.py", line 203, in file
plugin_manager.hook.attach_file(source=source, name=name, attachment_type=attachment_type, extension=extension)
File "/Users/userA/Documents/git/addr/test-framework/pytool/test_case_layer/environment.py", line 233, in after_all
allure.attach.file(log_destination.parent, log_destination.name, allure.attachment_type.TEXT)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/behave/runner.py", line 545, in run_hook
self.hooks[name](context, *args)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/behave/runner.py", line 645, in run_model
self.run_hook("after_all", self.context)
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/behave/runner.py", line 824, in run_with_paths
return self.run_model()
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/behave/runner.py", line 804, in run
return self.run_with_paths()
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/behave/__main__.py", line 127, in run_behave
failed = runner.run()
File "/Users/userA/Library/Caches/pypoetry/virtualenvs/pytool-6R8xcXyw-py3.11/lib/python3.11/site-packages/behave/__main__.py", line 183, in main
return run_behave(config)
File "/Users/userA/Documents/git/addr/test-framework/pytool/cli/pytool_run.py", line 48, in pytool_run_with_allure
main(command.split())
File "/Users/userA/Documents/git/addr/test-framework/pytool/cli/pytool_run.py", line 223, in <module>
pytool_run_with_allure()
File "/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 88, in _run_code
exec(code, run_globals)
File "/opt/homebrew/Cellar/[email protected]/3.11.5/Frameworks/Python.framework/Versions/3.11/lib/python3.11/runpy.py", line 198, in _run_module_as_main
return _run_code(code, main_globals, None,
KeyError: None
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem
in environment.py:
def after_all(context):
global log_destination
allure.attach.file(log_destination, log_destination.name, allure.attachment_type.TEXT)
It seems like the problem comes from https://github.com/allure-framework/allure-python/blob/master/allure-python-commons/src/reporter.py#L72. All tests where executed and the list contains only elements of type TestResultContainer and not of type ExecutableItem which lead the method to return a None.
The None is propagated cross the framework which lead to a KeyError.
What is the expected behavior?
The log to be attached and no error printed.
What is the motivation / use case for changing the behavior?
We want to attach the logs to the allure reports after all features where called.
Please tell us about your environment:
- Allure version: 2.13.2
- Test framework: [email protected]
- Allure adaptor: [email protected]
Other information
Hi, @sebastianpfischer! Thanks for the issue. Session scoped fixtures aren't implemented in allure-behave. Once they are, attachments from before_all/after_all will go there. Can't tell you the date estimate for this though, sorry.