RobotFramework,为每个套件执行不同的拆卸操作

时间:2017-12-01 12:59:52

标签: robotframework

*** Settings ***
Suite Teardown  Perform suite teardown

*** Keywords ***
Perform suite teardown
    Log to console          Test suite cleanup
    cleanUp                 ${a}  ${b}  ${c}

*** Test Cases ***
TEST 1
    do some action

TEST 2
    do another action

上面的代码运行良好并运行套件拆卸。我有一个场景,我想为每个测试用例运行不同的拆卸操作,如何修改上面的示例来做到这一点?

2 个答案:

答案 0 :(得分:5)

您的问题似乎正在使用"套件"什么时候应该使用"测试用例"。您的示例仅显示单个套件,套件拆解仅影响此套件。

如果您希望每个测试都有单独的拆解,您可以在每个测试中使用class Brand(models.Model): category = models.ForeignKey(Category, related_name='category', limit_choices_to={'parent_category__isnull': True}) sub_category = models.ForeignKey(Category, related_name='sub_category', limit_choices_to={'parent_category__isnull': False}) brand_code = models.CharField(max_length=70, null=True, blank=True) brand_name = models.CharField(max_length=255) def __str__(self): return self.brand_name def create_brand_code(self): pass def clean(self): if not self.sub_category.parent_category == self.category: raise ValidationError("{} is not the sub category of {}".format(self.sub_category, self.category)) def save(self, *args, **kwargs): if not self.brand_code: if self.sub_category.parent_category == self.category: self.brand_code = self.create_brand_code() super(Brand, self).save(*args, **kwargs)

[teardown]

有关更多信息,请参阅机器人框架用户指南中的Test Setup and Teardown

答案 1 :(得分:1)

这实际上是一个非常独特的解决方案。但是Lets说你想到处都没有[Teardown] ....

*** Settings ***

Test Teardown      Teardown ${TEST_NAME}


*** Variables ***

*** Test Cases ***
Test1
    [Tags]                             example
    Log To Console    ${TEST NAME}

*** Keywords ***
Teardown Test1
    Log To Console     I DID IT

这有点落伍......但有点酷