我尝试使用 pytest-bdd 为我的 API Python 项目进行设计。我制作了“通用、功能、测试”文件夹。
在功能文件中,我添加了我的帖子、删除、获取、放置案例。我还分开了 post.feature delete.feature 等。由于丢失了案例。
然后我从功能文件中生成了我的 post_steps.py。并且所有步骤页面中都有一些通用步骤。所以我决定把它们放到 common 文件夹下的 commonsteps.py 中。
然后,在 common.py 中,有一些常用方法如下断言状态码:
@then('Status code of response should be 200')
def status_code_of_response_should_be_200():
assert status_code == 200
我的测试从 mypost.py 开始,然后开始使用这种常用方法,但是如何将响应、状态代码传递到此页面?因为我需要验证。简而言之,如何从不同的步骤页面获取响应作为参数?在此处输入图像描述