Unittest difference with pytest-conditions before and after the automated testing framework python

Preface:

I have set conditions before and after the first try of the used unittest conditions and pytest front and rear, and front and rear that conditions pytest simple than unittest to be, a lot easier. However, when using the set conditions before and after the unittest has been compared to that in each test case inside and repeat the same front and rear write the code, unittest the front and rear is also simple, a lot easier.

Unittest provided before and after the counter: and the like is divided into front and rear of the front and rear of each test

Class pre-conditions:

  • setUpClass: mainly used to launch the browser and set the drive to maximize the browser window, and add open url, complete automation of pre-web
  • tearDownClass: mainly used to close the browser answer

Each test case of pre-conditions:

  • setUp \ tearDown: go write according to their own business logic
1     # entire test class pre-conditions (mainly for starting browser driver and settings to maximize the browser window and open the URL) 
2      @classmethod
 . 3      DEF setUpClass (CLS):
 . 4          # Start browser driver 
. 5          cls.driver = webdriver.Chrome ()
 . 6          # maximize the display window 
. 7          cls.driver.maximize_window ()
 . 8          # input url open 
. 9          cls.driver.get (cd.login_url)
 10          Print ( " start test " )
 . 11  
12 is      # cases with each execution preconditions 
13 is      DEF the setUp (Self):
 14          self.lp =The LoginPage (self.driver)
 15  
16      # postcondition embodiment with each execution 
. 17      DEF the tearDown (Self):
 18 is          # after execution of each embodiment, refresh the current page 
. 19          self.driver.get (cd.login_url)
 20 is  
21 is      # whole postcondition test class (mainly for the end, close the browser answer) 
22 is      @classmethod
 23 is      DEF tearDownClass (CLS):
 24          cls.driver.quit ()
 25          Print ( " test end " )

pytest the front and rear: fixture (mainly about the fixture)

fixture of the front and rear conftest.py file written inside, conftest without importing, which can be placed in one test class. Writing a test method front and rear, with a yield to distinguish between front and rear.

 

 

 

 
 
pytest.fixture @ (scope = "function")
 DEF start_app (): 
    Driver = init_cps ()
     # real machine confirmation access to 
    BL (Driver) .get_permission ()
     # slide operation 
    BP (driver) .cross_screen (times = 3, = LOC ll.now_start) 
# is a precondition to the yield, the latter yield is postconditions
yield Driver

 

Guess you like

Origin www.cnblogs.com/cuitang/p/11639961.html