Behave: How to import steps from another file?

好久不见. 提交于 2019-12-05 13:33:11

In the imported file, the behave decorators (like then) must be imported:

from behave import then
from nose.tools import assert_equals

@then('response status code is {expected_status_code}')
def step_impl(context, expected_status_code):
    assert_equals(context.response.status_code, int(expected_status_code))

...

Just for all people out there, that are (like me) trying to import the single step-definition: Don't!

Simply import the whole module.

And here for all pepole (like me...) that still need more details:

If your project structure looks like this:

foo/bar.py
foo/behave/steps/bar_steps.py
foo/behave/bar.feature
foo/common_steps/baz.py

Just do

import foo.common_steps.baz

in foo/behave/steps/bar_steps.py (that is your regular step file)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!