allure-python icon indicating copy to clipboard operation
allure-python copied to clipboard

'attach.file()' method cause 'KeyError: None' in case using that for attache file in step.

Open IgorZn opened this issue 5 years ago • 7 comments

I'm submitting a ...

  • [ ] bug report

What is the current behavior?

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem

demo.py

import time from behave import * from hamcrest import assert_that, equal_to, greater_than_or_equal_to from features.steps.shared_steps import parse_number

from allure_commons._allure import attach from allure_commons.types import AttachmentType

@Then('Get marked substance DEMO') def step_impl(context): # source, dest and third are substances 1, 2 and 3. # 1 and 2 are using as a start and end point fro drag and drop

source = context.shared_selectors.common_locators['first_cell_canvasContainer']
dest = context.shared_selectors.common_locators['second_cell_canvasContainer']
third = context.shared_selectors.common_locators['third_cell_canvasContainer']

context.ex_source = context.browser.find_element_wait(source).text
context.ex_source_2 = context.browser.find_element_wait(dest).text
context.ex_source_3 = context.browser.find_element_wait(third).text

# select two rows
context.browser.drag_and_drop_elem(source, dest)
context.browser.screenshot('error_screenie')

attach.file('error_screenie.png', name='Demo attach', attachment_type=AttachmentType.PNG)

Output: Traceback (most recent call last): File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\behave\model.py", line 1329, in run match.run(runner.context) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\behave\matchers.py", line 98, in run self.func(context, *args, **kwargs) File "features\steps\demo.py", line 24, in step_impl attach.file('error_screenie.png', name='Demo attach', attachment_type=AttachmentType.PNG) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\allure_commons_allure.py", line 167, in file plugin_manager.hook.attach_file(source=source, name=name, attachment_type=attachment_type, extension=extension) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\pluggy\hooks.py", line 289, in call return self._hookexec(self, self.get_hookimpls(), kwargs) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\pluggy\manager.py", line 87, in _hookexec return self._inner_hookexec(hook, methods, kwargs) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\pluggy\manager.py", line 81, in firstresult=hook.spec.opts.get("firstresult") if hook.spec else False, File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\pluggy\callers.py", line 208, in _multicall return outcome.get_result() File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\pluggy\callers.py", line 80, in get_result raise ex[1].with_traceback(ex[2]) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\pluggy\callers.py", line 187, in _multicall res = hook_impl.function(*args) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\allure_behave\listener.py", line 185, in attach_file self.logger.attach_file(uuid4(), source, name=name, attachment_type=attachment_type, extension=extension) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\allure_commons\reporter.py", line 112, in attach_file file_name = self._attach(uuid, name=name, attachment_type=attachment_type, extension=extension) File "D:\Users<username>\PycharmProjects\myproject\venv\lib\site-packages\allure_commons\reporter.py", line 107, in _attach self._items[last_uuid].attachments.append(attachment) KeyError: None

What is the expected behavior?

No exception.

What is the motivation / use case for changing the behavior?

Please tell us about your environment:

allure-behave==2.8.5 allure-python-commons==2.8.5 atomicwrites==1.3.0 attrs==19.1.0 beautifulsoup4==4.7.1 behave==1.2.6 certifi==2019.6.16 chardet==3.0.4 colorama==0.4.1 configparser==3.7.4 crayons==0.2.0 cucumber-tag-expressions==1.1.2 future==0.17.1 idna==2.8 importlib-metadata==0.18 lxml==4.4.1 more-itertools==7.2.0 packaging==19.1 parse==1.12.0 parse-type==0.4.2 pluggy==0.12.0 py==1.8.0 PyHamcrest==1.9.0 pyparsing==2.4.2 pyperclip==1.7.0 pytest==5.1.2 python-dateutil==2.8.0 pytz==2019.1 requests==2.22.0 selenium==3.141.0 six==1.12.0 soupsieve==1.9.2 urllib3==1.25.3 vertica-python==0.9.3 wcwidth==0.1.7 webdriver-manager==1.7 zipp==0.5.1

Other information

At the same time screenshot/document will APPEAR in destination folder, in my sace it's 'allure_report'

but I have to use try/except to avoid error.

IgorZn avatar Sep 13 '19 10:09 IgorZn

Tnx. Where it step called, regular scenario or something else?

sseliverstov avatar Sep 13 '19 10:09 sseliverstov

Tnx. Where it step called, regular scenario or something else?

regular scenario. Just a simple feature file as any other, nothing special.

IgorZn avatar Sep 13 '19 10:09 IgorZn

if this:

from allure_commons._allure import attach

Change to

from allure import attach
#...
attach.file(...)
#...

or better:

import allure
#...
allure.attach.file(...)
#...

sseliverstov avatar Sep 13 '19 10:09 sseliverstov

allure.attach.file(...)

hmm, it seems to be working! I'll double check and let you know a bit later.

IgorZn avatar Sep 13 '19 10:09 IgorZn

OK)

sseliverstov avatar Sep 13 '19 10:09 sseliverstov

So, I think we can close the issue. Some comments on my end: -- no KeyError in case use that in step; -- KeyError in case use somewhere else: fixture, your own class and so on. try/except KeyError will help you to fix that;

It will be nice to have a key such as: attach.file(no_uuid=true)

@sseliverstov Thanks for your support!

IgorZn avatar Sep 19 '19 12:09 IgorZn

This issue is still actual in 2022. When parametrizing with pytest_generate_tests allure causes 'KeyError: None'

sanchos avatar Aug 25 '22 22:08 sanchos

Hi, @sanchos !

The original issue with allure-behave was resolved, so I'm closing this. If you faced a bug while using allure-pytest with pytest_generate_tests, please, do not hesitate to open another one.

delatrie avatar Dec 05 '22 12:12 delatrie