import pytest
@pytest.fixture(autouse=True,params=[‘user1’,‘user2’,‘user3’])
def login():
print(“登录方法”)
yield [‘username’,‘password’]
print(“teardown”)

@pytest.mark.parametrize(‘login’,
[(1,2),(3,4)])
def test_car(login):
print(“你好”)
print(f"{login}")

返回结果
login.py::test_car[login0] PASSED [ 50%]你好
(1, 2)

login.py::test_car[login1] PASSED [100%]你好
(3, 4)

import pytest
@pytest.mark.parametrize(‘a,b’,[(1,2),(3,4)])

def test_car1(a,b):
print(“你好”)
返回结果
pytest之传递参数的方法
从返回结果来看,一个是把参数传递给了login,从而让login执行相应的测试用例。并且可以得到返回值。

相关文章:

  • 2021-12-01
  • 2021-05-27
  • 2021-12-12
  • 2021-08-23
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-07
  • 2022-02-19
  • 2021-10-15
  • 2022-12-23
  • 2021-11-23
  • 2021-06-23
相关资源
相似解决方案