如何在执行该类的所有其他方法之前运行一次pytest方法

时间:2019-04-20 15:29:22

标签: python-3.x pytest

@pytest.mark.usefixtures("oneTimeSetup","setUp")
class SignUpFLow2(unittest.TestCase):
    print("running once")@pytest.fixture(autouse=True)
    def classSetup(self,oneTimeSetup):
        print("running twice")

        self.nhp = Noon_home_page(self.driver)
        self.nrp = Noon_Regional_Page(self.driver)
        self.nsas = Noon_signup_Page(self.driver)
        self.nso = Noon_Sign_Out(self.driver)
        self.nsi = Noon_SignIn(self.driver)
        self.xl = xcelReading()
        xlw = write_to_excel()
        xl1 = xlsReadingvig()

        path = xlw.writing()
        print(path)

        column_length = xl1.columnCount()
        print(column_length)

        for i in range(0, column_length):
            self.cell_value1 = xl1.excel(0, i, path)
            self.cell_value2 = xl1.excel(0, i + 1, path)
            self.cell_value3 = xl1.excel(0, i + 2, path)
            break
        self.value1 = self.cell_value1
        self.value2 = self.cell_value2
        self.value3 = self.cell_value3@pytest.mark.run(order=1)
    def test2(self):
        print("first test running")
        result = self.nhp.verifyLoginSuccessfull()
        self.nhp.Click()
        time.sleep(2)
        self.nhp.ClickLanguage()
        assert result == True  # asserting noon icon on home page

    @pytest.mark.run(order=2)
    def test3(self):
        print("Second test running")
        self.nrp.Click()
        time.sleep(2)
        result1 = self.nrp.verifyTitle()
        self.nrp.SignUpClick()
        assert result1 == True # asserting page title

0 个答案:

没有答案