说明
在日常使用pytest写自动化测试用例时,经常会写一些前置的fixtrue操作,当其测试用例有用到时就直接传该函数的参数名称就可以了,但有时候用例很多的时候,每次都传这个参数的话会显得比较冗余、麻烦。
针对这样的情况,pytest早就已经替我们想到了,fixture 里面有个参数 autouse,默认是 Fasle 没开启的,可以设置为True 开启,就可以自动使用了,也就是说不用再手动传参就可以自动运行该用例了。
方法使用
那autouse要怎么使用呢,其实就是在引用fixtrue写前置用例时,传一个autouse=True就可以了。具体看如下代码:
```python
import pytest
import time
@pytest.fixture(scope='module',autouse=True)
def start(request):
print('********开始执行module********')
print('module:%s'%request.module.__name__)
print('*******启动浏览器********')
yield
print('********结束测试 end!********')
@pytest.fixture(scope='function',autouse=True)
def open_home(r