如何在测试(或方法)中自动使用pytest设备?

2024-06-16 14:43:26 发布

您现在位置:Python中文网/ 问答频道 /正文

鉴于我找到的信息here,我尝试了以下操作:

@pytest.mark.usefixtures("driver")
class TestSuite(object):
    def test1(self):
        driver.log("Start the test")

但我有个错误

^{pr2}$

所以信息是不正确的,还是我误解了?在

如何在TestSuite类内的每个测试方法(或任何其他方法)中自动使用fixture?在

更多信息:

  • 我需要夹具为每一个测试重新初始化
  • 通常一个测试需要5个固定装置。但由于我每次考试都会用到一些方法,所以我需要像这样把它们全部通过

    def do_something(self, fixture1, fixture2, fixture3, fixture4, fixture5):
        ...
    
    def test1(self, fixture1, fixture2, fixture3, fixture4, fixture5):
         do_something(fixture1, fixture2, fixture3, fixture4, fixture5)
    

    也许不会太糟,但如果我能在每次测试中自动使用夹具,那将有助于。。。


Tags: 方法self信息defdriverdosomething夹具
1条回答
网友
1楼 · 发布于 2024-06-16 14:43:26

{这意味着你的代码中不会自动调用它们。在

我怀疑有没有一种方法可以在没有明确命名的情况下使用fixture。在

class TestSuite(object):
    def test1(self, driver):
        driver.log("Start the test")

是唯一的办法。在

相关问题 更多 >