pytest_ parametric 3

Import pytest 
test_user_data = [
{ 'User': 'Linda', 'password': '8888'},
{ 'User': 'servenruby', 'password': '123456'},
{ 'User': 'Test01', 'password': ''}
]

@ pytest.fixture (scope = 'Module1')
DEF login_r (Request):
# dict can form, while passing a parameter, but can be achieved by a number of parameters passed exhausted key way effect
user request.param = [ 'user']
pwd = request.param [ 'password']
Print ( '\ n-open Home prepared login, user login% s, password S%'% (user, pwd))
IF pwd :
return True
the else:
return False

# this is pytest parameter-driven, indeirect = True is the login_r as a function to perform
@ pytest.mark.parametrize ( 'login_r', test_user_data ,= True the INDIRECT)
DEF test_cart (login_r):
# landing embodiment
a = login_r
print ( 'test of the return value login_r S%'% A)
Assert A, 'the cause of failure, the password is empty'

Home ready to open landing, landing user linda, password 8888
PASSED [33%] in login_r test the return value of True

Home ready to open landing, landing user servenruby, password 123456
PASSED [66%] in login_r test the return value of True

Home ready to open landing, landing user test01, password
FAILED [100%] test case login_r the return value of False


Home ready to open landing, landing user linda, password 8888
PASSED [33%] in login_r test the return value of True

Home ready to open landing, landing user servenruby, password 123456
PASSED [66%] in login_r test the return value of True

Home ready to open landing, landing user test01, password
FAILED [100%] test case login_r the return value of False

test_mark_param_request2.py:19 (test_cart[login_r2])
login_r = False

pytest.mark.parametrize @ ( 'login_r', test_user_data, the INDIRECT = True)
DEF test_cart (login_r):
# landing Example
A = login_r
Print ( 'test case login_r return value S%'% A)
> A Assert, ' failure reasons, the password is blank '
E AssertionError: failure reasons, the password is blank
E assert False

Guess you like

Origin www.cnblogs.com/QaStudy/p/11565894.html