首页 > 其他分享 >pytest + yaml 框架 -39.多账号操作解决方案

pytest + yaml 框架 -39.多账号操作解决方案

时间:2023-11-02 12:44:06浏览次数:38  
标签:39 账号 url test8 yaml token pytest

前言

最近有小伙伴提到,有写场景需要用到2个账号来回切换操作该如何解决。
备注:从v1.2.4 以后新版本不再公开,新功能内部 VIP 学员可以使用,公开版本仅解决bug, 不提供新功能了。

先获取账号token

前面教程有讲到全局登录一次,后面所有的请求都会拿着全局登录的账号token去访问请求。
现在需要新增2个账号,那我们只需要得到2个账号的token即可

conftest.py 通过fixture去分别拿到test8 和 test9 账号的token

from pytest_yaml_yoyo.http_session import HttpSession


@pytest.fixture(scope="session")
def token1(environ):
    s = HttpSession(base_url=environ.BASE_URL)
    body = {
            "username": "test8",
            "password": "123456"
    }
    r = s.send_request("post", "/api/v1/login", json=body)
    token = r.json()['token']
    return token


@pytest.fixture(scope="session")
def token2(environ):
    s = HttpSession(base_url=environ.BASE_URL)
    body = {
            "username": "test9",
            "password": "123456"
    }
    r = s.send_request("post", "/api/v1/login", json=body)
    token = r.json()['token']
    return token

调用pytest_yaml_yoyo.http_session 内部封装的 HttpSession,只需传相对路径即可发搜请求。
base_url 地址通过 config.py 中设置的环境地址BASE_URL (参考多环境切换的配置), 获取方式:environ.BASE_URL

yaml 用例中传不同 token

test_more_user.yml

config:
  fixtures: token1,token2

user1:
-
  name: 账号test8操作
  request:
    url: /api/v1/userinfo
    method: get
    headers:
      Authorization: Token ${token1}
  validate:
    - eq: [$.code, 0]
-
  name: 账号test8继续操作
  print: test8继续操作

user2:
  name: 账号test9操作
  request:
    headers:
      Authorization: Token ${token2}
    url: /api/v1/userinfo
    method: get
  validate:
    - eq: [$.code, 0]

标签:39,账号,url,test8,yaml,token,pytest
From: https://www.cnblogs.com/yoyoketang/p/17488106.html

相关文章

  • Keras TypeError: ('Keyword argument not understood:', 'input')
    TypeError:('Keywordargumentnotunderstood:','input') model=Model(input=[inputs],output=output)报错信息TypeError:('Keywordargumentnotunderstood:','input')解决方法换成model=Model(inputs=...,outputs=...) ......
  • Not creating XLA devices, tf_xla_enable_xla_devices not set TypeError: 'mod
     2021-02-2622:54:13.146272:Itensorflow/core/common_runtime/gpu/gpu_device.cc:1406]CreatedTensorFlowdevice(/job:localhost/replica:0/task:0/device:GPU:0with2989MBmemory)->physicalGPU(device:0,name:GeForceGTX1050,pcibusid:0000:01:0......
  • KEIL软件的Error: Flash Download failed - Could not load file '..\OBJ\Template.
    Error:FlashDownloadfailed - Couldnotloadfile'..\OBJ\USART.axf' 解决方案:1重新覆盖安装keil2程序编译存在错误导致 同时开多个KEIL,只有其中一个KEIL可以使用J-LINK,ST-LINK。 ......
  • AttributeError: 'Series' object has no attribute 'ix'
    在pandas版本0.20.0及其以后版本中,ix已经不被推荐使用,建议采用iloc和loc实现ix。 predictions_ARIMA_log=pd.Series(ts_log.ix[0],index=ts_log.index)predictions_ARIMA_log=predictions_ARIMA_log.add(predictions_ARIMA_diff_cumsum,fill_value=0)predictions_ARIMA_log.he......
  • TypeError: fit() got an unexpected keyword argument 'nb_epoch'
    model.fit(trainX,trainY,nb_epoch=200,batch_size=2,verbose=2) It'sjust epochs now. nb_epoch wasdeprecatedyearsago. 把nb_epoch......
  • Your shell has not been properly configured to use 'conda activate'.
     #./condaactivatepy38CommandNotFoundError:Yourshellhasnotbeenproperlyconfiguredtouse'condaactivate'.Toinitializeyourshell,run   $condainit<SHELL_NAME>Currentlysupportedshellsare: -bash -fish -tcsh -xonsh -......
  • in org.springframework.cache.annotation.ProxyCachingConfiguration required a be
    我的项目是springboot项目,在启动过程中报错如何下Parameter0ofmethodcacheAdvisorinorg.springframework.cache.annotation.ProxyCachingConfigurationrequiredabeanoftype'org.springframework.cache.interceptor.CacheOperationSource'thatcouldnotbefound......
  • 《CF1889C2 Doremy's Drying Plan (Hard Version)》 解题报告
    考场上不会做。如果考虑删掉哪些区间实际上不太可做。正难则反,转化贡献,考虑哪些点可以有贡献。显然一个点如果可能有贡献,那么当且仅当覆盖它的区间\(\leK\)个。于是我们记一个状态\(f_{i,j}\)表示前\(i\)个点中,\(i\)是最后一个贡献的点,已经删除了\(j\)段区间了。......
  • CF1039D You Are Given a Tree
    CF1039DYouAreGivenaTree更好的阅读体验一种神奇套路:对答案根分,根分的依据是链的长度和答案大致是一个成反比的关系。考虑确定了\(k\)怎么做。因为一个点只能在一条链里,所以dfs的时候如果能拼成一条链就一定会拼成一条链,不然就把贡献传给父亲继续尝试。对于\(k\)比......
  • jenkins和allure配置,构建后没有'Allure Report'选项
    Allure插件已安装 全局设置 AllureCommandline但是构建后操作,还是没有AllureReport'选项  AllureCommandline换成手动的,也还是不行 系统属性中也增加allure配置  还是没有解决。。。。。。。。。。。。。。。。。。。。。。。。......