Python- unittest为什么SetUpClass给出了attribue错误

时间:2017-02-10 18:03:30

标签: python selenium-webdriver pytest python-unittest

我正在使用unittest和pytest

@pytest.mark.usefixtures("oneTimeSetUp","setUp")
@ddt
class SendformTest(unittest.TestCase):


    @pytest.fixture(autouse=True)
    def classSetup(self,oneTimeSetUp):
        self.sf = SendForms(self.driver)
        self.ts = TestStatus(self.driver)

    @classmethod
    def setUpClass(self):  ############ I want this method to run just once after login
        self.sf.navigateToCCForms("img")

当我尝试运行这个时,我得到一个属性错误 AttributeError:type object' SendformTest'没有属性' sf'

1 个答案:

答案 0 :(得分:0)

虽然我并不完全熟悉pytest,但是快速谷歌搜索将我带到了关于使用pytest with unittest.TestCase的页面。底部的注释说明:

  

unittest.TestCase方法无法直接接收fixture函数参数,因为实现可能会对运行通用unittest.TestCase测试套件的能力造成影响

所以我的猜测是你的灯具永远不会运行,导致你的setUp方法失败。

相关问题