前言
青年最主要的任务是学习。—— 朱德
正值青年的我的任务!!!
一、autouse参数是什么?
- autouse参数是fixture方法中的其中一个参数;(ps:为了防止有些朋友单独看这篇博文才写了这句)
- autouse从英文字面意思上来理解是自动使用;
- autouse参数设置后能自动让范围内的测试方法都执行。
二、autouse参数应用
- 2.1 没有使用autouse参数的代码:
import pytest
@pytest.fixture()
def setUp():
print('\nsetUp')
yield
print('\ntearDown')
def testcase01(setUp):
print('exectue testcase01')
assert 1
def testcase02(setUp):
print('exectue testcase02')
assert 1
if __name__=='__main__':
pytest.main(["-s"])
- 2.2 使用autouse参数的代码:
import pytest
@pytest.fixture(autouse=True) #设置为True让autouse生效
def setUp():
print('\nsetUp')
yield
print('\ntearDown')
def testcase01():
print('exectue testcase01')
assert 1
def testcase02():
print('exectue testcase02')
assert 1
if __name__=='__main__':
pytest.main(["-s"])
上述两个实例小结:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。