Python更改pytest打印测试格式

Python更改pytest打印测试格式,python,testing,pytest,Python,Testing,Pytest,我希望改变pytest将测试结果打印到屏幕上的方式 这是我的代码: @pytest.mark.parametrize('公式,结果', [('4-3',对),('3*(50+2',对)]) def测试检查某物V2(方程式、结果): 断言公式\u验证。检查字符串\u有效性(公式)=结果 现在,当我在终端中使用“pytest-v-s”时,输出如下所示: > test_calculator.py::test_check_somethingv2[4-3-True] PASSED > te

我希望改变pytest将测试结果打印到屏幕上的方式

这是我的代码:

@pytest.mark.parametrize('公式,结果',
[('4-3',对),('3*(50+2',对)])
def测试检查某物V2(方程式、结果):
断言公式\u验证。检查字符串\u有效性(公式)=结果
现在,当我在终端中使用“pytest-v-s”时,输出如下所示:

> test_calculator.py::test_check_somethingv2[4-3-True] PASSED
> test_calculator.py::test_check_somethingv2[4-3: True] PASSED
我希望输出如下所示:

> test_calculator.py::test_check_somethingv2[4-3-True] PASSED
> test_calculator.py::test_check_somethingv2[4-3: True] PASSED
我知道我可以使用“ids=['4~3:True',…]”为每个测试手动设置它,但是因为我将处理许多测试,所以我希望有一种比这更简单的方法

还有,是否有这样的输出选项

>  test_check_somethingv2[4-3: True] PASSED

一种方法是围绕
pytest.param
编写包装器,例如:

def eqparam(等式,结果):
返回pytest.param(eq,result,id=f'{eq}:{result}')
@pytest.mark.parametize('公式,结果',
[eqparam('4-3',正确),eqparam('3*(50+2'),正确)])
def测试检查某物V2(方程式、结果):
断言公式\u验证。检查字符串\u有效性(公式)=结果
其结果如下:

$ pytest --collect-only t.py
============================== test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
rootdir: /home/asottile/workspace/pygments-pre-commit
collected 2 items                                                               
<Module t.py>
  <Function test_check_somethingv2[4-3: True]>
  <Function test_check_somethingv2[3*(50+2): True]>

============================= no tests ran in 0.01s =============================
$pytest--仅收集t.py
==============================================测试会话开始==============================
平台linux——Python 3.6.8、pytest-5.3.2、py-1.8.1、pluggy-0.13.1
rootdir:/home/asotile/workspace/pygments预提交
收集2项
==============================================0.01秒内未运行任何测试=============================

一种方法是围绕
pytest.param
编写包装,例如:

def eqparam(等式,结果):
返回pytest.param(eq,result,id=f'{eq}:{result}')
@pytest.mark.parametize('公式,结果',
[eqparam('4-3',正确),eqparam('3*(50+2'),正确)])
def测试检查某物V2(方程式、结果):
断言公式\u验证。检查字符串\u有效性(公式)=结果
其结果如下:

$ pytest --collect-only t.py
============================== test session starts ==============================
platform linux -- Python 3.6.8, pytest-5.3.2, py-1.8.1, pluggy-0.13.1
rootdir: /home/asottile/workspace/pygments-pre-commit
collected 2 items                                                               
<Module t.py>
  <Function test_check_somethingv2[4-3: True]>
  <Function test_check_somethingv2[3*(50+2): True]>

============================= no tests ran in 0.01s =============================
$pytest--仅收集t.py
==============================================测试会话开始==============================
平台linux——Python 3.6.8、pytest-5.3.2、py-1.8.1、pluggy-0.13.1
rootdir:/home/asotile/workspace/pygments预提交
收集2项
==============================================0.01秒内未运行任何测试=============================