Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/345.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:无法同时指定参数和计数_Python_Python 3.x_Pytest - Fatal编程技术网

Python Pytest:无法同时指定参数和计数

Python Pytest:无法同时指定参数和计数,python,python-3.x,pytest,Python,Python 3.x,Pytest,我尝试使用--count选项多次运行带有参数的测试。 这不起作用,因为--count选项用数字更改收集的测试名称。 带有参数化测试的简单代码: 导入pytest 导入日志记录 logger=logging.getLogger(_名称__) pytestmark=pytest.mark.register() @pytest.mark.parametrize(“param_a”),[(((“val1”),(“val2”),(“val3”)) def测试功能(子管理控制器,参数a): 通过 运行测试

我尝试使用--count选项多次运行带有参数的测试。 这不起作用,因为--count选项用数字更改收集的测试名称。 带有参数化测试的简单代码:

导入pytest
导入日志记录
logger=logging.getLogger(_名称__)
pytestmark=pytest.mark.register()
@pytest.mark.parametrize(“param_a”),[(((“val1”),(“val2”),(“val3”))
def测试功能(子管理控制器,参数a):
通过
运行测试:

(venv) [bob@bob tests]$ pytest test_demo.py --collect-only

collected 3 items
<Package /bob/tests>
  Folder containing all testcases.
  <Module test_demo.py>
    <Function test_func[val1]>
    <Function test_func[val2]>
    <Function test_func[val3]>

========================================================================================================= no tests ran in 0.04s ==========================================================================================================
(venv) [bob@bob tests]$ pytest test_demo.py --collect-only --count=2

collected 6 items
<Package /bob/tests>
  Folder containing all testcases.
  <Module test_demo.py>
    <Function test_func[val1-1-2]>
    <Function test_func[val1-2-2]>
    <Function test_func[val2-1-2]>
    <Function test_func[val2-2-2]>
    <Function test_func[val3-1-2]>
    <Function test_func[val3-2-2]>

========================================================================================================= no tests ran in 0.04s ==========================================================================================================
(venv) [bob@bob tests]$ pytest test_demo.py::test_func[val1] --collect-only --count=2

collected 0 items

========================================================================================================= no tests ran in 0.05s ==========================================================================================================
ERROR: not found: /bob/tests/test_demo.py::test_func[val1]
(no name '/bob/tests/test_demo.py::test_func[val1]' in any of [<Module test_demo.py>])

(venv) [bob@bob tests]$ pytest test_demo.py::test_func[val1-1-2] --collect-only --count=2

collected 1 item
<Package /bob/tests>
  Folder containing all testcases.
  <Module test_demo.py>
    <Function test_func[val1-1-2]>

========================================================================================================= no tests ran in 0.04s ==========================================================================================================
(venv)[bob@bob测试]$pytest\u demo.py--仅收集
收集了3个项目
包含所有测试用例的文件夹。
===========================================================================================================================================================================================================================================================================0.04秒内没有运行任何测试==========================================================================================================
(venv)[bob@bob测试]$pytest\u demo.py--仅收集--计数=2
收集6项
包含所有测试用例的文件夹。
===========================================================================================================================================================================================================================================================================0.04秒内没有运行任何测试==========================================================================================================
(venv)[bob@bobtests]$pytest test\u demo.py::test\u func[val1]--仅收集--计数=2
收集了0个项目
==============================================================================================================================================================================================================================================================================0.05秒内没有运行任何测试==========================================================================================================
错误:未找到:/bob/tests/test_demo.py::test_func[val1]
(在任何[]中都没有名称“/bob/tests/test_demo.py::test_func[val1]”)
(venv)[bob@bobtests]$pytest\u demo.py::test\u func[val1-1-2]--仅收集--计数=2
收集1项
包含所有测试用例的文件夹。
===========================================================================================================================================================================================================================================================================0.04秒内没有运行任何测试==========================================================================================================

如何多次运行特定的子测试?

您最好在项目中询问这个问题-我猜这是不受支持的。是的,它似乎不受支持。在调用测试的参数选择部分使用通配符也会有所帮助。您可以使用此方案创建功能请求(或者更好地使用这样做的PR)。