[英]How to handle session which is generated in the setup and teardown methods in pytest in another file test_1.py
def setup_method(usern,pwd):
global token,session
inputdata=''
session = requests.Session()
inputdata={
"username":"XXXXXt",
"password":"<XXXxx"
}
response = session.post(config.login_url,data=inputdata,headers=config.api_headers)
token = json.loads(response.text).get('token')
config.api_headers["X-CSRF-Token"]=json.loads(response.text).get('token')
def teardown_method():
inputdata=''
config.api_headers["X-CSRF-Token"]=token
session.post(config.logout_url,data=inputdata,headers=config.api_headers)
#print("logout:",token)
#assert (json.loads(response.text)).get('ResponseStatus') in "SUCCESS"
How to handle session which is generated in the setup and teardown methods in pytest in another file test_1.py
?如何处理另一个文件 test_1.py 中 pytest 的设置和拆卸方法中生成的
test_1.py
?
Please use conftest.py for the same - please refer to this documentation available at https://docs.pytest.org/en/2.7.3/plugins.html?highlight=re请使用 conftest.py - 请参阅https://docs.pytest.org/en/2.7.3/plugins.ZFC35FDC70D5FC69D269883A822C7high?light?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.