Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

YAML support removed in v8

Đang mở
#785 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
30/100
Loại issue
Tính năng
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
testing-qa

Hướng nghiên cứu

Bắt đầu bằng cách kiểm tra pytest_bdd/gherkin_parser.py quanh dòng 316 và tái hiện CompositeParserException đã báo cáo với một feature chứa phần thân step có dạng giống YAML. Đọc hành vi của trình phân tích cú pháp Gherkin bên dưới và xác định một cú pháp cụ thể cùng phạm vi phân tích cú pháp có thể bảo toàn các biến Gherkin. Công việc được xem là hoàn tất khi cú pháp được chọn phân tích thành công và hỗ trợ các kiểu tham số tùy chỉnh cho dữ liệu step có cấu trúc.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Context

In previous versions of pytest-bdd, it was possible to define steps that included inline YAML-like syntax, which made it much easier to write complex or parameterized tests. For example:

Given a new resource with:
    id: 1234
    name: new resource
    data: any-data

and then parse those parameters using a custom parser:

@given(parsers.cfparse(
    'a new resource with:\n{resource_parameters:yaml}',
    extra_types={"yaml": yaml.safe_load}
))
def _(resource_parameters):
    id = resource_parameters["id"]
    # test code

Current Problem

Since version 8 of pytest-bdd, it seems that changes introduced in the underlying Gherkin parser (via gherkin-official) have made this syntax invalid.
Running tests written this way now produces the following parser error:

.venv/lib/python3.10/site-packages/pytest_bdd/gherkin_parser.py:316: in get_gherkin_document
gherkin_data = Parser().parse(feature_file_text)
.venv/lib/python3.10/site-packages/gherkin/parser.py:79: in parse
state = self.match_token(state, token, context)
.venv/lib/python3.10/site-packages/gherkin/parser.py:222: in match_token
return state_map[state](token, context)
.venv/lib/python3.10/site-packages/gherkin/parser.py:1104: in match_token_at_15
self.add_error(context, error)
.venv/lib/python3.10/site-packages/gherkin/parser.py:97: in add_error
raise CompositeParserException(context.errors)
E gherkin.errors.CompositeParserException: Parser errors:
E (9:13): expected: #EOF, #TableRow, #DocStringSeparator, #StepLine, #TagLine, #ExamplesLine, #ScenarioLine, #RuleLine, #Comment, #Empty, got 'id: 1234'

Expected Behavior / Feature Proposal

It would be extremely helpful to support YAML-like syntax blocks inside Gherkin steps again — either through:

Allowing indentation-based content as a valid part of a step body,

Or by supporting a new syntax (e.g., fenced blocks or docstrings with a yaml type hint) that can be parsed using custom parameter types.

This feature would allow writing structured input directly in .feature files, while still enabling parameterization via Gherkin variables.

Motivation

YAML-style parameter blocks make test scenarios much more readable and maintainable, especially when working with APIs or data-rich test cases.
This capability was previously possible using cfparse with custom extra_types, and restoring it (or providing an alternative) would improve developer ergonomics significantly.

It would be important that any future implementation of this feature continues to support the use of Gherkin variables inside the YAML-like syntax, as this was previously a key advantage for writing parameterized and data-driven tests directly in feature files:

Given a new resource with:
    id: <id>

Examples:
    | id |

Thank you in advance

Ngôn ngữ chính
Python
Star
1.5k
Fork
253
Merge trung bình
4 giờ 30 phút
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pytest-dev/pytest-bdd

Tất cả issue của pytest-dev/pytest-bdd

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.