私は Flask チュートリアルに従っており、現在 Behave を使用したビヘイビア駆動型開発を検討しています。
私の仕事は、BDD を使用して、1 人のユーザーがログイン、ログアウトし、ブログ投稿を作成できるようにする、非常に基本的なブログ アプリケーションを構築することです。
機能ファイル、ステップ ファイル、および環境ファイルを作成しました。次に、ユーザーがログインおよびログアウトできるようにするコードを作成しました。
アプリケーションをローカルで実行して手動でテストすると、期待どおりに機能し、ユーザーがログインおよびログアウトして必要なテキスト (「ログインしました」または「ログアウトしました」) を表示できるため、問題を想定しています。アプリケーション コードではなく、機能ファイルまたはステップ ファイルを使用します。
Behave を実行すると、最終ステップが「未定義」のように見えます。
機能ファイルの関連部分は次のとおりです。
Feature: flaskr is secure in that users must log in and log out to access certain features
Scenario: successful login
Given flaskr is setup
When we log in with "admin" and "admin"
Then we should see the alert "You were logged in"
Scenario: successful logout
Given flaskr is setup
and we log in with "admin" and "admin"
When we log out
Then we should see the alert "You were logged out"
私の手順ファイルは次のとおりです。
from behave import *
@given(u'flaskr is setup')
def flask_is_setup(context):
assert context.client
@given(u'we log in with "{username}" and "{password}"')
@when(u'we log in with "{username}" and "{password}"')
def login(context, username, password):
context.page = context.client.post('/login',
data=dict(username=username,
password=password),
follow_redirects=True
)
assert context.page
@when(u'we log out')
def logout(context):
context.page = context.client.get('/logout', follow_redirects=True)
assert context.page
@then(u'we should see the alert "{message.encode("utf-8")}"')
def message(context, message):
assert message in context.page.data
環境ファイルから:
def before_feature(context, feature):
context.client = app.test_client()
問題と思われるのは、最後の「その後」のステップです。チュートリアルの解決策を確認して他の場所を検索しようとしましたが、コードのこの部分を解決できないようです。Python バージョン 3.5 を使用しているため、メッセージをエンコードする必要がありました (関連する場合、チュートリアルではバージョン 2.7 を使用していました)。
任意のポインタは非常に高く評価されます。