GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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 #280

New issue
Copy link
New issue
Copy link
Closed
#732
Closed
Allure throws UnicodeDecodeError when recieve \\u in test parameter value#280
#732
Copy link
Labels
bugSomething isn't workingSomething isn't workingcontributeCall for a contributionCall for a contributiongood first issueGood for newcomersGood for newcomerstheme:pytest

Description

@grmmvv
grmmvv
opened on Aug 3, 2018
Issue body actions

I'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:

  • Allure version: 2.7.0
  • Test framework: [email protected]
  • Allure adaptor: [email protected]
  • Python version: 2.7.15

Other information

Without --alluredir argument exception is not appears

Activity

  1. vdsbenoit commented on Oct 11, 2018

    @vdsbenoit
    vdsbenoit
    on Oct 11, 2018
    More actions

    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')

  2. delatrie
    added
    bugSomething isn't workingSomething isn't working
    theme:pytest
    on Dec 5, 2022
  3. delatrie commented on Dec 13, 2022

    @delatrie
    delatrie
    on Dec 13, 2022
    Contributor
    More actions

    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.

  4. delatrie commented on Dec 19, 2022

    @delatrie
    delatrie
    on Dec 19, 2022
    Contributor
    More actions

    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.

  5. delatrie
    added
    good first issueGood for newcomersGood for newcomers
    contributeCall for a contributionCall for a contribution
    on Dec 19, 2022
  6. delatrie
    closed this as completedin #732on Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't workingcontributeCall for a contributionCall for a contributiongood first issueGood for newcomersGood for newcomerstheme:pytest

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.