4

this is my test script:

@pytest.mark.parametrize('data', [0, 1], ids=['有效', '无效'])
def test_a(data):
    assert 1

but the name of each id is escaped both in Pycharm and Terminal:
enter image description here
enter image description here

So, how to fix this?

Chweng Mega
  • 1,598
  • 1
  • 13
  • 22
  • print a.decode('utf-8').encode('gb2312') Dont know if this is the right encode. Similar question here https://stackoverflow.com/questions/2688020/how-to-print-chinese-word-in-my-code-using-python – BioFrank Jun 22 '18 at 09:50
  • that's not a same story – Chweng Mega Jun 22 '18 at 09:53
  • 1
    `pytest` escapes parametrized ids, this can't be reconfigured. See [issue #2482](https://github.com/pytest-dev/pytest/issues/2482) for details. – hoefling Jun 22 '18 at 14:00

1 Answers1

4

As of April 2019, pytest supports this via the following configuration setting in pytest.ini or other configuration:

disable_test_id_escaping_and_forfeit_all_rights_to_community_support = True

With that configuration, the example in the question works as designed without changes.

This setting is documented here.

Note: as the name implies, community support may be unavailable for issues caused while running in this configuration, and it may cause issues on Windows, use it with care.

The change was merged via pull request no. 4995, and a discussion of the somewhat esoteric-née-discouraging name (and possible issues that can occur with this setting) can be found in the linked issue (no. 2482).

Zac B
  • 3,796
  • 3
  • 35
  • 52