首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >python行为不检测步骤文件

python行为不检测步骤文件
EN

Stack Overflow用户
提问于 2018-06-13 19:09:00
回答 1查看 7.7K关注 0票数 1

我对Python很陌生,行为举止也不错。我正试图为我的自动化项目设置一个POC。我遵循了“行为”文档中的教程,但是当我运行“行为”时,它抛出的步骤是不可检测的。我遗漏了什么?

我的文件夹结构是这样的。

代码语言:javascript
复制
/features/testone.feature
/features/steps/testone_steps.py

特征文件

代码语言:javascript
复制
Feature: Running sample feature

@smoke @regression
Scenario: Login to github and verify it works in testone feature of scenario one
Given Launch GITHUB app with "test@test.com" and "githubtest"

step文件

代码语言:javascript
复制
from behave import given, when, then, step

@given(u'Launch GITHUB app with "{text}" and "{text}"')
def step_impl(context, user, password):
    print(f"This is the given step with {user} and {password}")

输出

代码语言:javascript
复制
λ behave
Feature: Running sample feature # features/testone.feature:1

  @smoke @regression
  Scenario: Login to github and verify it works in testone feature of scenario one  # features/testone.feature:4
    Given Launch GITHUB app with "test@test.com" and "githubtest"                   # None


Failing scenarios:
  features/testone.feature:4  Login to github and verify it works in testone feature of scenario one

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

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

@given(u'Launch GITHUB app with "test@test.com" and "githubtest"')
def step_impl(context):
    raise NotImplementedError(u'STEP: Given Launch GITHUB app with "test@test.com" and "githubtest"')

我在vscode编辑器中注意到,在steps文件中,pylint显示了以下消息。

代码语言:javascript
复制
[pylint] E0611:No name 'given' in module 'behave'
[pylint] E0611:No name 'when' in module 'behave'
[pylint] E0611:No name 'then' in module 'behave'
[pylint] E0611:No name 'step' in module 'behave'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-06-14 15:05:51

您的问题是在step文件中使用了不正确的格式。试试这个:

代码语言:javascript
复制
from behave import given, when, then, step

@given(u'Launch GITHUB app with "{user}" and "{password}"')
def step_impl(context, user, password):
    print("This is the given step with {user} and {password}".format(user, password))

注意,@given语句中定义的参数与step_impl()中传递的参数匹配。

也就是说,如果在@given中,您有

@given(u'Launch GITHUB app with "{user}" and "{password}"')

那么在您的步骤实现中,您应该

def step_impl(context,user,password)

如果没有此匹配,并且在当前代码中,您将收到NotImplementedError,因为parameters正在寻找一个步骤实现,其中的参数是contexttext作为步骤文件中的参数,即def step_impl(context, text)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50844576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档