【问题标题】:after.each_scenario hook is not working(not available) in aloe_djangoafter.each_scenario 钩子在 aloe_django 中不起作用(不可用)
【发布时间】:2015-11-30 11:18:43
【问题描述】:

我想在一个功能的每个场景之后执行一些操作(清除 cookie、清除数据库等),但是 after.each_feature 在 aloe_django 中不可用。你是如何处理这个问题的。处理此问题的任何建议。以下钩子在 aloe_django 中不可用。

@before.each_scenario def setup_some_scenario(scenario): populate_test_database()

我需要这个,因为我想在一个功能中有多个场景,当第一个功能完成后,我从管理员注销并需要在下一个场景中再次登录(不注销没有帮助),但在下一个场景它给出了一个错误,告诉我我的凭据无效(在第一个场景中它是有效的)。 当我将此场景作为不同的功能并重置我的数据库并迁移时,它工作正常。

我认为当它在功能中从一个场景跳转到另一个场景时,它会弄乱数据库或使用不同的数据库,所以我需要 after.each_scenario() 挂钩来重置和迁移我的数据库。

【问题讨论】:

  • 放一些代码,这就是其他开发人员的原因。能理解你的问题。

标签: django python-3.x bdd lettuce


【解决方案1】:

我在 Aloe_django 中使用了 before/after.each_example() 钩子。 您将这段代码放入您的terrain.py 文件中。

@before.each_example def before_each_example(scenario,outline,steps): call_command(#your command#)

【讨论】:

    【解决方案2】:
    You could use @After tag, 
    
    Example:
    
    @Clean up
    Scenario Outline: eating
      Given there are <start> cucumbers
      When I eat <eat> cucumbers
      Then I should have <left> cucumbers
    
      Examples:
        | start | eat | left |
        |  12   |  5  |  7   |
        |  20   |  5  |  15  |
    
    In step definition,
    
    @After("Clean up")
    public void cleanup(){
    
    System.out.println("CLEAN UP RUNNING ");
    
    }
    
    
    After every scenario, Your test will call this after function and do cleaning job.
    

    【讨论】:

    • 感谢您的建议。我已经解决了芦荟中的 each_example() 钩子的问题
    • 请评论整个解决方案。它会帮助别人。
    • 已经提交了更准确的答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-12
    • 2020-09-24
    相关资源
    最近更新 更多