(三)pytest中配置文件及函数的使用
一、conftest.py的作用范围
一个工程下可以建多个conftest.py的文件,一般在工程根目录下设置的conftest文件起到全局作用。在不同子目录下也可以放conftest.py的文件,作用范围只能在该层级以及以下目录生效。

二、跳过测试函数

import pytest
class Test_ABC():
def setup_class(self):
print('\n------>setup_class')
def teardown_class(self):
print('------>teardown_class')
def test_d(self):
print('------>test_d')
assert 1
@pytest.mark.skipif(condition=2>1,reason='跳过该函数')
def test_f(self):
print('------>test_f')
assert 0
if __name__ == '__main__':
pytest.main("-s test_skipif.py")
三、标记为预期失败函数

import pytest
class Test_ABC():
def setup_class(self):
print('\n------>setup_class')
def teardown_class(self):
print('------>teardown_class')
def test_d(self):
print('------>test_d')
assert 1
@pytest.mark.xfail(2>1,reason='标注为预期失败')
def test_f(self):
print('------>test_f')
assert 0
if __name__ == '__main__':
pytest.main("-s test_xfail.py")
四、函数数据参数化





浙公网安备 33010602011771号