pytest ---- fixture (1) - to perform configuration using the fixture and the destruction of logic

1 Use fixture to perform configuration and on Their Destruction; very flexible use.
2 Data Sharing: write method may be implemented in conftest.py configuration where data sharing is not required import introduced. Across file sharing
3scope level and magical combination of yield is equivalent to a variety of setup and teardown
 
Use fixture to perform configuration and on Their Destruction logic
Scene: The test case execution, and some examples of data stored in the database, you need to connect to the database and then execute test cases, the final stop connection to the database. setup and teardown can be achieved. fixture flexibility named achieve. The default scope (range) function

• Step:
1. Import pytest

2. In the above function plus landing @ pytest.fixture ()

3. Incoming (login function name) in the test method to be used, the landing on the first landing 4. not passed is not directly perform the test methods.

 

pytest.fixture @ () 
DEF the Login ():
Print ( "\ the n-enter a user name password")

DEF test_cart (the Login):
Print ( 'Use Case 1, after landing add shopping cart functionality to perform operations')

DEF test_search ():
print ( 'with Example 2, no login operation inquiry')

DEF test_pay (login):
print ( 'with Example 3, the function performs the payment operation after landing

pytest_fixture.py::test_cart
enter a username password
PASSED [33%] used in Example 1, after landing operation performed add shopping cart functionality

pytest_fixture.py::test_search PASSED [66%] of Example 2, the query function without logging operation

pytest_fixture.py::test_pay
enter a username password
PASSED [100%] used in Example 3, the function performs the payment operation login

 

Guess you like

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