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

Test files and features files to be in different directories

如何在py-test-bdd中制作不同目录下的测试文件和特征文件?

我查看了 "Organizing your scenarios" 部分下的 py-test 文档。

我当前的结构是:

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.feature 并且显然它抛出一个错误目录不存在。
我如何让它做 bdd/features/log.feature ?

只需执行../ 即可跳转到上一级目录。即:

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

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

如果你有不止一种场景,那么只需在顶部声明一个变量并将这个变量传递给每个@scenario,即:

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

@scenario(myFilePath, 'scenario title #2')
@blah