上一篇文章寫到fixture中的scope參數的使用,本篇文章主要寫params參數的使用;params是fixture函數中的一個可選參數列表,它將導致多個參數調用fixture函數和所有測試使用它。
conftest.py 文件 @pytest.fixture(scope='session',params=['chrome','firefox']) def fix_test(request): print('----- 創建瀏覽器驅動器對象 -----') yield request.param print('銷毀瀏覽器驅動器對象')
測試用例文件 class Test_web(): def test1(self,fix_test): print('%s-----打開京東'%fix_test) def test2(self,fix_test): print('%s-----打開唯品會' % fix_test)
可以看到結果是根據params參數值運行了兩次測試用例;可以通過fixture函數的scope參數控制作用域;