Behave / python3:即使步进函数存在,也测试未定义

问题描述 投票:1回答:1

我已经开始使用behave来定义Python3上的行为驱动测试。第一次测试很顺利,但现在我遇到了一个最令人费解的错误。

我已经定义了这个Gherkin文件sra-to-isatab-batch-conversion.feature

Feature: SRA to ISA-tab Batch conversion
# perform a batch conversion of a set of SRA datasets, retrieved from the European Nucleotide Archive
# to ISA-tab

Scenario: Batch conversion form a list of SRA accession numbers
 Given An access number "ERA000084"
 And nothing else
 When the SRA to ISA tab conversion is invoked
 Then it should return a ZIP file object
 And the ZIP file should contain as many directories as the element in the list

然后我在文件steps/sra-to-isatab-batch-conversion.py中定义以下步骤方法

from behave import *

use_step_matcher("parse")


@given('An access number "{access_number}"')
def step_impl(context, access_number):
    context.access_number = access_number
    print(context.access_number)

@step("nothing else")
def step_impl(context):
    print("Nothing else") 


@when("the SRA to ISA tab conversion is invoked")
def step_impl(context):
 pass


@then("it should return a ZIP file object")
def step_impl(context):
    pass


@step("the ZIP file should contain as many directories as the element in the list")
def step_impl(context):
    pass

如果我然后运行behave sra-to-isatab-conversion.feature,则与when步骤相关的步骤函数似乎缺失:

Feature: SRA to ISA-tab Batch conversion # sra-to-isatab-batch-conversion.feature:2

Scenario: Batch conversion form a list of SRA accession numbers                  # sra-to-isatab-batch-conversion.feature:6
Given An access number "ERA000084"                                             # steps/sra-to-isatab-batch-conversion.py:6 0.000s
And nothing else                                                               # steps/sra-to-isatab-batch-conversion.py:40 0.000s
When the SRA to ISA tab conversion is invoked                                  # None
Then it should return a ZIP file object                                        # None
And the ZIP file should contain as many directories as the element in the list # None

/Users/massi/Projects/oerc/isa-api/features/test_outputs

Failing scenarios:
  sra-to-isatab-batch-conversion.feature:6  Batch conversion form a list of SRA accession numbers

0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
2 steps passed, 0 failed, 2 skipped, 1 undefined
Took 0m0.001s

You can implement step definitions for undefined steps with these snippets:

@when(u'the SRA to ISA tab conversion is invoked')
def step_impl(context):
    raise NotImplementedError(u'STEP: When the SRA to ISA tab conversion is invoked')`

我试图重新定义步骤描述更改给定语句的数量,我甚至重写了文件,但我总是得到同样的错误。即使我复制错误消息中建议的语句,我仍然会得到相同的错误。

谁能解释一下我做错了什么?我正在使用Python 3.4 Behave 1.2.5 PyCharm 5.0.4(注意PyCharm BDD工具识别Gherkin文件和步骤函数中的语句之间的匹配)

python python-3.x gherkin python-behave
1个回答
0
投票

嗯,它目前正好适合我,你的确切实现,如上面粘贴。可能是环境问题或安装问题。你能尝试重新安装吗?你也是从你的终端或pycharm运行它?

PS:不是问题,但如果您使用parse,则不需要指定use_step_matcher()方法;因为它是默认的step_matcher

另外(确保不会出现粘贴的人为错误):@when step方法在“pass”语句中有缩进问题。它在您的代码中是否真的像这样,或者只是论坛中的格式问题?

© www.soinside.com 2019 - 2024. All rights reserved.