代码之家  ›  专栏  ›  技术社区  ›  theQuestionMan

测试文件和功能文件位于不同的目录中

  •  1
  • theQuestionMan  · 技术社区  · 10 年前

    如何在py-test-bdd中的不同目录中创建测试文件和特性文件?

    我看过“组织您的场景”部分下的py测试文档。

    我目前的结构是:

    bdd
      |
      feature directory
                      |
                      feature file #1 (named log.feature)
                      feature file #2
                      feature file #3      
      |
      test file #1
      test file #2
      test file #3
    

    当前代码执行以下操作:

    @scenario('features/log.feature', 'scenario description #1')
    

    但实际上我想要的是:

    bdd
      |
      feature directory
                      feature file #1
                      feature file #2
                      feature file #3      
      |
      test directory (named tests)
                    test file #1
                    test file #2
                    test file #3
    

    我试着写代码:

    @scenario('bdd/features/log.feature', 'scenario description #1')
    

    但是,当执行上面的这行时,实际上要做的是bdd/tests/bdd/features/log。特性,显然它抛出了一个错误目录。
    我如何让它做bdd/features/log。特色

    1 回复  |  直到 10 年前
        1
  •  0
  •   theQuestionMan    10 年前

    只需执行../即可跳转到前面的目录。即:

    @scenario('../features/log.feature', 'scenario title #1')
    

    如果您有更多的目录,只需执行../../../,并重复../,重复次数与您想要的目录一样多。

    如果您有多个场景,那么只需在顶部声明一个变量,并将该变量传递给每个@场景,即:

    myFilePath = '../features/log.feature'
    @scenario(myFilePath, 'scenario title #1')
    @given('blah....')
    @then('blah....')
    
    @scenario(myFilePath, 'scenario title #2')
    @blah