标签:数据 from art 定义变量 tps object def ble baidu
1 import requests,pytest 2 from Learning.variable import * 3 4 # 定义变量 5 #url = "https://www.baidu.com" 6 7 class TestClass(object): 8 global url #在此获取全局变量,并将其设置为TestClass类的全局变量 9 def setup_class(self): 10 print("start...") 11 12 def test_get(self): 13 #global url #在此获取全局变量,并将其设置为test_get方法内的全局变量 14 res = requests.get(url=url) 15 assert res.status_code == 200 16 17 18 if __name__ == ‘__main__‘: 19 pytest.main()
# content of test01.py import pytest,requests #将conftest中的com_variable方法传入用例中,不需要导入即可使用 def test_getBaidu(com_variable): a=requests.get(com_variable[‘url‘]) code = a.status_code assert code == 200 def test_paas(): pass
# content of conftest.py import pytest iaas={ ‘url‘:‘https://www.baidu.com‘, } @pytest.fixture(scope="module") def com_variable(): return iaas
conftest不变,直接在class中的方法入参中传入即可
import requests,pytest from Learning.variable import * # 定义变量 #url = "https://www.baidu.com" class TestClass(object): #global url #在此获取全局变量,并将其设置为TestClass类的全局变量 def setup_class(self): print("start...") #直接在此传入即可 def test_get(self,com_variable): #global url #在此获取全局变量,并将其设置为test_get方法内的全局变量 res = requests.get(url=com_variable[‘url‘]) assert res.status_code == 200 if __name__ == ‘__main__‘: pytest.main()
标签:数据 from art 定义变量 tps object def ble baidu
原文地址:https://www.cnblogs.com/phyger/p/11366620.html