conftest.py 810 B

12345678910111213141516171819202122232425262728
  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, clear_yaml_projectCode, read_testcase, read_config_yaml, write_yaml
  7. path = Path(__file__).parent.glob("**/test_001_登录接口.yaml")
  8. for yaml_path1 in path:
  9. yaml_path=yaml_path1
  10. @pytest.fixture(scope="session", autouse=True)
  11. def clear_yam():
  12. clear_yaml()
  13. login_system(yaml_path)
  14. def login_system(yaml_path: Path):
  15. global i
  16. data = read_testcase(yaml_path)
  17. for i in data:
  18. method = i['request'].pop("method")
  19. url =read_config_yaml("base", "base_qccq_sc")+ i['request'].pop("url")
  20. # 发送请求
  21. res = requests.request( method, url, **i['request'])
  22. token = res.json()['data']["token"]
  23. write_yaml({"token":token})