GeezerVison is showing github.com — Allure throws UnicodeDecodeError when recieve \\u in test parameter value · Issue #280 · allure-framework/allure-python
Allure throws UnicodeDecodeError when recieve \\u in test parameter value #280DescriptionI'm submitting a ...
- 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?
Allure cant escape test name when meet \\u in test parameter value and throws UnicodeDecodeError exception.
Reproduction
Run code below with argument --alluredir=somedir
import pytest
@pytest.mark.parametrize('param', ['\\u'])
def test_decode_error( param):
pass
Trace:
pytest test_allure.py --alluredir=allure-results -v
============================= test session starts =============================
platform win32 -- Python 2.7.15, pytest-3.7.1, py-1.5.4, pluggy-0.7.1 -- c:\git\allure_error\venv\scripts\python.exe
cachedir: .pytest_cache
rootdir: C:\GIT\allure_error, inifile:
plugins: allure-pytest-2.5.0
collected 1 item
test_allure.py::test_decode_error[C:\source\unigine.vcxproj-/p:Platform=x64] ERROR [100%]
=================================== ERRORS ====================================
ERROR at setup of test_decode_error[C:\source\unigine.vcxproj-/p:Platform=x64]
self = <allure_pytest.listener.AllureListener object at 0x06697590>
item = <Function 'test_decode_error[C:\\source\\unigine.vcxproj-/p:Platform=x64]'>
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_setup(self, item):
uuid = self._cache.set(item.nodeid)
test_result = TestResult(name=item.name, uuid=uuid)
self.allure_logger.schedule_test(uuid, test_result)
yield
uuid = self._cache.get(item.nodeid)
test_result = self.allure_logger.get_test(uuid)
for fixturedef in _test_fixtures(item):
group_uuid = self._cache.get(fixturedef)
if not group_uuid:
group_uuid = self._cache.set(fixturedef)
group = TestResultContainer(uuid=group_uuid)
self.allure_logger.start_group(group_uuid, group)
self.allure_logger.update_group(group_uuid, children=uuid)
params = item.callspec.params if hasattr(item, 'callspec') else {}
> test_result.name = allure_name(item, params)
venv\lib\site-packages\allure_pytest\listener.py:78:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv\lib\site-packages\allure_pytest\utils.py:88: in allure_name
name = escape_name(item.name)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
name = 'test_decode_error[C:\\source\\unigine.vcxproj-/p:Platform=x64]'
def escape_name(name):
if six.PY2:
try:
name.decode('string_escape').encode('unicode_escape')
except UnicodeDecodeError:
return name.decode('string_escape').decode('utf-8')
> return name.encode('ascii', 'backslashreplace').decode('unicode_escape')
E UnicodeDecodeError: 'unicodeescape' codec can't decode bytes in position 27-28: truncated \uXXXX escape
venv\lib\site-packages\allure_pytest\utils.py:108: UnicodeDecodeError
Environment:
Other information
Without --alluredir argument exception is not appears Activityvdsbenoit commented on Oct 11, 2018 This is due to a bad interpretation of the backslashes. A quickfix is to insert a replace('\\','/') statement in allure_pytest/utils.py:
return name.replace('\\','/').encode('ascii', 'backslashreplace').decode('unicode_escape') delatrie commented on Dec 13, 2022 The escape_name function was originaly introduced to deal with pytest parameter encoded as unicode literals in a nodeid like this:
==== test session starts ====
platform linux -- Python 3.11.0, pytest-7.2.0, pluggy-1.0.0 -- /...
rootdir: /...
plugins: ...
collected 2 items
tests/test_i280.py::test_fn[\U0001f3b5] PASSED [ 50%]
tests/test_i280.py::test_fn[\U0001f3b6] PASSED [100%]
==== 2 passed in 0.16s =====
Previously we would have constructed the following full names: test.test_i280#test_fn[🎵] and test.test_i280#test_fn[🎶] (see #171).
But starting from 2.8.0 we don`t put parameter values in test full names anymore, so both tests end up with the same full name: test.test_i280#test_fn.
So basically, we can (and I will, as soon as I have time) just dispose of the escape_name entirely. As long as there are no backslashes in a nodeid, everything should be fine (and the only place where a backslash could appear AFAIK is a parameter section which, again, is omitted now from the test name). I`m going to keep this issue as a reminder for myself, but I am closing the corresponding PR. delatrie commented on Dec 19, 2022 If someone wants to contribute, please, feel free to take this issue. Is`s an easy one - just remove allure-pytest`s utils.escape_name from the code base.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|