python - 不正确的清新使用测试结果

标签 python testing bdd nose nosetests

我刚刚安装了 Freshen,正在尝试掌握它的窍门。

下面的测试运行,但它给出的输出不正确。

测试:get_user.feature

Feature: Retrieve an existing User
    When a Users ID (ID, Email, User-name) is entered,
    An object containing all the Users information is returned

    Scenario: Get existing User from their ID
        Given I have the user where their id is '288' and account id is '57'
        Then their username should equal adminuserxxx

步骤.py

from freshen import *
from freshen.checks import *

import user_operations
import util
#The URL of the API
api_root = "http://api.stuff.com/v1/core";

#The ID of the Application
appid = "1234567";

#Our private key
secret = "987654321";

#Headers
headers = {'Accept':'application/json', 'Content-Type':'application/json'}

@Before
def before(sc):
    scc.headers = headers
    util.get_auth_token_and_scope(api_root, appid, secret, scc.headers) #An authorization token is added to scc.headers here

@Given("I have the user where their id is (\d+) and account id is (\d+)")
def enter(user_id,account_id):
    scc.user = user_operations.get_user_from_id(int(account_id), int(user_id), scc.headers)

@Then("their (\w+) should equal (\w+)")
def check_result(field_value, result):
    assert_equal(str(result),scc.user[str(field_name)])

控制台输出:

C:\Users\Front-End>nosetests --with-freshen -v features\
Retrieve an existing User: Get existing User from their ID ... UNDEFINED: "I hav
e the user where their id is '288' and account id is '57'" # features\get_user.f
eature:6

----------------------------------------------------------------------
Ran 1 test in 0.137s

OK (UNDEFINED=1)

有人能指出我做错了什么吗?干杯!

最佳答案

如果您在 @Given 函数中使用 (\d+) ...(\d+),该功能应该具有这种语法(假设我有用户,他们的 ID 是 288 并且帐户 ID 是 57)

M.Harbaoui

关于python - 不正确的清新使用测试结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21142074/

相关文章:

python - 创建没有相似交叉的列表

testing - 通过 Selenium WebDriver 在浏览器的同一窗口 session 中打开一个新选项卡?

rest - 如何在 Postman 测试中读取环境变量?

c# - 连接到单元测试中的事件

cucumber - Python 行为 : How to read examples from external excel file for Scenarios Outline

python - 我想知道为什么循环不会在这里停止

python - 如何沿 x 轴移动图形?

unit-testing - 如何在 Jasmine 中使用多个期望

unit-testing - TDD 和 BDD 之间的主要区别是什么?

python - WebSocket 在 1000 条消息后关闭