conftest.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import json
  2. import os
  3. from pathlib import Path
  4. import pytest
  5. import requests
  6. from common.yaml_util import clear_yaml, read_testcase, read_config_yaml, write_yaml, clear_out_yaml
  7. path = Path(__file__).parent.glob("**/test_001_登录接口.yaml")
  8. for yaml_path1 in path:
  9. yaml_path = yaml_path1
  10. # path = Path(__file__).parent.glob("**/test_001_登录接口验证码.yaml")
  11. # for yaml_path1 in path:
  12. # yzm_path = yaml_path1
  13. @pytest.fixture(scope="session", autouse=True)
  14. def clear_yam():
  15. clear_yaml()
  16. clear_out_yaml()
  17. login_system(yaml_path)
  18. def login_system(yaml_path: Path):
  19. global i
  20. data = read_testcase(yaml_path)
  21. for i in data:
  22. method = i['request'].pop("method")
  23. url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
  24. # 发送请求
  25. res = requests.request(method, url, **i['request'])
  26. token = res.json()['data']["token"]
  27. write_yaml({"token": token})
  28. # def yzm_login(yzm_path):
  29. # global i
  30. # data = read_testcase(yzm_path)
  31. # for i in data:
  32. # method = i['request'].pop('method')
  33. # url = read_config_yaml("base", "base_qccq_sc") + i['request'].pop("url")
  34. # res = requests.request(method, url, **i['request'])
  35. # print(111111111111111111,res)