allure-framework / allure-framework/allure-python
Allure attachment fails in after_all() method of python-behave framework
- Dominant language
- Python
- Stars
- 814
- Forks
- 260
- PR merge metrics
- No merged PRs in 30d
Description
[//]: # (
. Note: for support questions, please use Stackoverflow or Gitter**.
. This repository's issues are reserved for feature requests and bug reports.
.
. In case of any problems with Allure Jenkins plugin** please use the following repository
. to create an issue: https://github.com/jenkinsci/allure-plugin/issues
.
. Make sure you have a clear name for your issue. The name should start with a capital
. letter and no dot is required in the end of the sentence. An example of good issue names:
.
. - The report is broken in IE11
. - Add an ability to disable default plugins
. - Support emoji in test descriptions
)
#### 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:
```python
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
pytool_run_with_allure()
File "/opt/homebrew/Cellar/python@3.11/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/python@3.11/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`:
``` python
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: behave@1.2.6
- Allure adaptor: allure-behave@2.13.2
#### Other information
[//]: # (
. e.g. detailed explanation, stacktraces, related issues, suggestions
. how to fix, links for us to have more context, eg. Stackoverflow, Gitter etc
)
Contributor guide
Research direction
Reproduce the issue with the shown after_all() example in environment.py, then inspect allure-python-commons/src/reporter.py around line 72 and allure-behave/listener.py around line 174. Trace how the missing item is propagated during Behave's after_all hook. Done means the log is attached to the Allure report without the KeyError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100