Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用pytest--collect only只返回单个测试名称_Python_Testing_Pytest - Fatal编程技术网

Python 使用pytest--collect only只返回单个测试名称

Python 使用pytest--collect only只返回单个测试名称,python,testing,pytest,Python,Testing,Pytest,我正在尝试整理如何使用pytest从测试文件中获取测试名称列表我已经完成了以下工作: $ pytest --collect-only my_test_file.py ============================================================================================= test session starts =====================================================

我正在尝试整理如何使用pytest从测试文件中获取测试名称列表我已经完成了以下工作:

$ pytest --collect-only my_test_file.py
============================================================================================= test session starts ==============================================================================================
platform darwin -- Python 3.6.4, pytest-3.2.5, py-1.5.2, pluggy-0.4.0
rootdir: /Users/.../automation, inifile:
plugins: xdist-1.20.1, metadata-1.7.0, html-1.17.0, forked-0.2, cloud-2.0.0
collected 6 items
<Module 'my_test_file.py'>
  <UnitTestCase 'TestFile'>
    <TestCaseFunction 'test_general'>
    <TestCaseFunction 'test_search_0'>
    <TestCaseFunction 'test_search_1'>
    <TestCaseFunction 'test_search_2'>
    <TestCaseFunction 'test_search_3'>
    <TestCaseFunction 'test_search_4'>
$pytest--仅收集我的测试文件.py
====================================================================================================================================测试会话开始==============================================================================================
平台darwin——Python 3.6.4、pytest-3.2.5、py-1.5.2、Plugy-0.4.0
rootdir:/Users/../automation,文件:
插件:xdist-1.20.1、metadata-1.7.0、html-1.17.0、forked-0.2、cloud-2.0.0
收集6项
虽然这是一个良好的开端,但信息太多了。我应该通过什么来获取测试名称列表呢

使用
--quiet
更改采集输出

$ pytest --collect-only -q
test_eggs.py::test_bacon[1]
test_eggs.py::test_bacon[2]
test_eggs.py::test_bacon[3]
test_spam.py::test_foo
test_spam.py::test_bar

no tests ran in 0.03 seconds
您可以使用

$ pytest --collect-only -q | head -n -2
当使用两次(或更多)时,
--quiet
将打印每个模块的测试量:

$ pytest --collect-only -qq
test_eggs.py: 3
test_spam.py: 2

-s
应该使输出更加简洁,我认为。。。但你不是在执行。。。也许没有effect@EPo,
-s
用于避免捕获输出,因此,例如,控制台中将显示打印语句。因此,这不是一个解决方案。答案正确,尽管这很奇怪,我认为这是pytest中的一个设计缺陷。为什么我要提供
--quiet
以便能够列出我的测试的全名?这毫无意义。