如何让pytest运行所有函数作为测试?

问题描述 投票:0回答:3

我环顾四周,找不到可以传递的 pytest.ini 标志,该标志相当于

def test_one():
   # you run this by default

def two():
   # despite not having test in the name you should also run this

原因:当我对命名进行描述时,测试函数名称长度变得很长,坦率地说,这似乎很反干。

python unit-testing testing pytest ini
3个回答
1
投票

来自文档

# content of setup.cfg
# can also be defined in in tox.ini or pytest.ini file
[pytest]
python_files=check_*.py
python_classes=Check
python_functions=*_check

*_check
替换为
*
即可。


0
投票

尝试如下所示,它会询问所有 python 文件中的 py.test 集合测试。

# content of pytest.ini
[pytest]
python_files = *.py

您可以查看文档的这部分,

自定义测试集合以查找所有 .py 文件


0
投票

您应该在

pytest.ini
中将 * 设置为 python_functions 来运行所有函数,如下所示:

# "pytest.ini"

[pytest]
python_functions = *

另外,如果你没有在

python_functions
中设置
pytest.ini
,如下所示,那么以
test
为前缀的函数将按照文档运行:

# "pytest.ini"

[pytest]
# python_functions = *
© www.soinside.com 2019 - 2024. All rights reserved.