pytest-dev / pytest-dev/pytest-html

Multi byte character method name is garbled

Open
#501 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
779
Forks
260
PR merge metrics
No merged PRs in 30d

Description

issue

When use unicode in test method,

    def test_あいうえお(self):
        print('かきくけこ')

I got garbled text (mojibake) in html reports.

test_あいうえお

reason

Method name ( report.nodeid ) is encoded as utf-8 and decoded as unicode_escape .

src/pytest_html/result.py

        self.test_id = report.nodeid.encode("utf-8").decode("unicode_escape")

Multi byte character as utf-8 is different same one as unicode_escape.

>>> print('abcdeあいうえお'.encode("utf-8"))
b'abcde\xe3\x81\x82\xe3\x81\x84\xe3\x81\x86\xe3\x81\x88\xe3\x81\x8a'
>>> print('abcdeあいうえお'.encode("unicode_escape"))
b'abcde\\u3042\\u3044\\u3046\\u3048\\u304a'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/pytest_html/result.py at the assignment to self.test_id, then reproduce the issue with a pytest test method containing the shown Japanese characters. Verify the HTML report preserves the method name and output without mojibake.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
54/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.