gpt4 book ai didi

python - pytest 是否支持测试名称中的 unicode?

转载 作者:行者123 更新时间:2023-12-04 16:45:39 28 4
gpt4 key购买 nike

这是我的测试样本(test_time.py):

#!/usr/bin/python
# -*- coding: utf-8 -*-

import pytest
from datetime import datetime, timedelta

testdata = [
(datetime(2001, 12, 12), datetime(2001, 12, 11), timedelta(1)),
(datetime(2001, 12, 11), datetime(2001, 12, 12), timedelta(-1)),
]

@pytest.mark.parametrize("a,b,expected", testdata, ids=[u"中文", u"English"])
def test_timedistance_v1(a, b, expected):
diff = a - b
assert diff != expected

这是pytest输出:
============================================================================== FAILURES ==============================================================================
_________________________________________________________________ test_timedistance_v1[\u4e2d\u6587] _________________________________________________________________

a = datetime.datetime(2001, 12, 12, 0, 0), b = datetime.datetime(2001, 12, 11, 0, 0), expected = datetime.timedelta(1)

@pytest.mark.parametrize("a,b,expected", testdata, ids=[u"中文", u"English"])
def test_timedistance_v1(a, b, expected):
diff = a - b
> assert diff != expected
E assert datetime.timedelta(1) != datetime.timedelta(1)

test_time.py:15: AssertionError
___________________________________________________________________ test_timedistance_v1[English] ____________________________________________________________________

a = datetime.datetime(2001, 12, 11, 0, 0), b = datetime.datetime(2001, 12, 12, 0, 0), expected = datetime.timedelta(-1)

@pytest.mark.parametrize("a,b,expected", testdata, ids=[u"中文", u"English"])
def test_timedistance_v1(a, b, expected):
diff = a - b
> assert diff != expected
E assert datetime.timedelta(-1) != datetime.timedelta(-1)

test_time.py:15: AssertionError
====================================================================== 2 failed in 0.05 seconds ======================================================================

输出中的第二行,测试名称是“test_timedistance_v1[\u4e2d\u6587]”,希望是“test_timedistance_v1[中文]”,py.test支持吗?
(我的pytest版本是3.1.2,操作系统:macOS 10.12.5)

最佳答案

它不取决于 pytest 而是取决于您的计算机语言环境。

这里是测试的跟踪日志( LC_ALL="en_US.UTF-8" ):

================================ test session starts ================================
platform linux -- Python 3.5.3, pytest-2.9.2, py-1.4.34, pluggy-0.3.1
rootdir: /home/..../tmp, inifile:
collected 2 items

pytest_chin.py FF

===================================== FAILURES ======================================
_____________________________ test_timedistance_v1[中文] ______________________________
...

并与 LC_ALL="fr_FR.iso8859-1" :
================================ test session starts ================================
platform linux -- Python 3.5.3, pytest-2.9.2, py-1.4.34, pluggy-0.3.1
rootdir: /home/gustavi/tmp, inifile:
collected 2 items

pytest_chin.py FF

===================================== FAILURES ======================================
\x1b[1m\x1b[31m_____________________________ test_timedistance_v1[\u4e2d\u6587] ______________________________\x1b[0m
...

Here在 OS X 上设置语言环境的有用链接。

关于python - pytest 是否支持测试名称中的 unicode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44903389/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com