お知らせ
2023.12.5(Tue)
目次
こんにちは、湯本です。
Ubuntu環境でTavernを使いAPIのリクエスト送信をしたところ、エラーが発生したので対処法を紹介します。
yaml.parser.ParserError: while parsing a block mapping
in “/home/user001/work/apiTest/test/comment_regist_test.tavern.yaml”, line 21, column 9
expected , but found ”
in “/home/user001/work/apiTest/test/comment_regist_test.tavern.yaml”, line 24, column 10
エラー発生時の環境は、下記の通りです。
yamlファイル
test_name: comment_regist_test includes: - !include common.yaml stages: # コメント登録テスト - name: comment_regist_test request: url: https://********.api method: POST headers: content-type: application/json; charset=utf-8 json: testId: "00000001" message: "コメント登録APIのテストを実施しています。" response: status_code: 200 json: status: errors: null returnCode: "200" successMsg: "更新が完了しました。"
user001:~/work/apiTest$ /home/user001/.local/bin/tavern-ci ./test/comment_regist_test.tavern.yaml
23行目の先頭に半角スペースが1つ多かったため構文エラーとなっていました。
全角スペースやタブを使ったインデントでもエラーが発生するため、半角スペースで正しくインデントされていることを確認する必要があります。
エラーメッセージにエラーとなった行番号が書かれているので、半角スペースで正しくインデントを揃えます。
今回は、23行目の半角スペースを1つ削除します。
修正後のyamlファイル
test_name: comment_regist_test includes: - !include common.yaml stages: # コメント登録テスト - name: comment_regist_test request: url: https://********.api method: POST headers: content-type: application/json; charset=utf-8 json: testId: "00000001" message: "コメント登録APIのテストを実施しています。" response: status_code: 200 json: status: errors: null returnCode: "200" successMsg: "更新が完了しました。"
今回は、半角スペースが1つ多い行があったためにエラーが発生しました。
エディタツールなどの設定で、スペースを表示して確認するとわかりやすいので、見直してみてください。
《関連記事》