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

test_step_outside_scenario_or_background_error fails with current gherkin-official

Đang mở
#779 1 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
45/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
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 với tests/parser/test_errors.py và chạy các môi trường tox py3.13-pytest8.3-gherkin_officiallatest và py3.13-pytest8.3-gherkin_official30 để so sánh lỗi. Điều tra cách phiên bản gherkin-official hiện tại xử lý step nằm ngoài Scenario hoặc Background, và hoàn tất khi test báo cáo FeatureError như mong đợi với dependency mới nhất và các parser test đều vượt qua.

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

Mô tả

Describe the bug

With the current gherkin-official (now 32.1.2), test_step_outside_scenario_or_background_error fails.

To Reproduce
Write a Minimal, Reproducible Example to show the bug.

$ git clone https://github.com/pytest-dev/pytest-bdd.git
$ cd pytest-bdd
$ tox -e py3.13-pytest8.3-gherkin_officiallatest
[…]
============================================== FAILURES ==============================================
___________________________ test_step_outside_scenario_or_background_error ___________________________

pytester = <Pytester PosixPath('/tmp/pytest-of-ben/pytest-19/test_step_outside_scenario_or_background_error0')>

    def test_step_outside_scenario_or_background_error(pytester):
        """Test step outside of a Scenario or Background."""
        features = pytester.mkdir("features")
        features.joinpath("test.feature").write_text(
            textwrap.dedent(
                """
                Feature: Invalid Feature
                # Step not inside a scenario or background
                Given a step that is not inside a scenario or background

                    Scenario: A valid scenario
                        Given a step inside a scenario

                """
            ),
            encoding="utf-8",
        )

        pytester.makepyfile(
            textwrap.dedent(
                """
                from pytest_bdd import scenarios, given

                @given("a step inside a scenario")
                def step_inside_scenario():
                    pass

                scenarios('features')
                """
            )
        )

        result = pytester.runpytest()

        # Expect the FeatureError for the step outside of scenario or background
>       result.stdout.fnmatch_lines(["*FeatureError: Step definition outside of a Scenario or a Background.*"])
E       Failed: nomatch: '*FeatureError: Step definition outside of a Scenario or a Background.*'
E           and: '======================================== test session starts ========================================='
E           and: 'platform linux -- Python 3.13.3, pytest-8.4.1, pluggy-1.6.0'
E           and: 'rootdir: /tmp/pytest-of-ben/pytest-19/test_step_outside_scenario_or_background_error0'
E           and: 'plugins: bdd-8.1.0'
E           and: 'collected 1 item'
E           and: ''
E           and: 'test_step_outside_scenario_or_background_error.py .                                            [100%]'
E           and: ''
E           and: '========================================= 1 passed in 0.01s =========================================='
E       remains unmatched: '*FeatureError: Step definition outside of a Scenario or a Background.*'

features   = PosixPath('/tmp/pytest-of-ben/pytest-19/test_step_outside_scenario_or_background_error0/features')
pytester   = <Pytester PosixPath('/tmp/pytest-of-ben/pytest-19/test_step_outside_scenario_or_background_error0')>
result     = <RunResult ret=0 len(stdout.lines)=9 len(stderr.lines)=0 duration=0.02s>

/home/ben/src/forks/pytest-bdd/tests/parser/test_errors.py:72: Failed
---------------------------------------- Captured stdout call ----------------------------------------
======================================== test session starts =========================================
platform linux -- Python 3.13.3, pytest-8.4.1, pluggy-1.6.0
rootdir: /tmp/pytest-of-ben/pytest-19/test_step_outside_scenario_or_background_error0
plugins: bdd-8.1.0
collected 1 item

test_step_outside_scenario_or_background_error.py .                                            [100%]

========================================= 1 passed in 0.01s ==========================================
====================================== short test summary info =======================================
FAILED tests/parser/test_errors.py::test_step_outside_scenario_or_background_error - Failed: nomatch: '*FeatureError: Step definition outside of a Scenario or a Background.*'
    and: '======================================== test session starts ========================================='
    and: 'platform linux -- Python 3.13.3, pytest-8.4.1, pluggy-1.6.0'
    and: 'rootdir: /tmp/pytest-of-ben/pytest-19/test_step_outside_scenario_or_background_error0'
    and: 'plugins: bdd-8.1.0'
    and: 'collected 1 item'
    and: ''
    and: 'test_step_outside_scenario_or_background_error.py .                                            [100%]'
    and: ''
    and: '========================================= 1 passed in 0.01s =========================================='
remains unmatched: '*FeatureError: Step definition outside of a Scenario or a Background.*'
============================= 1 failed, 137 passed, 1 skipped in 10.76s ==============================

Expected behavior

Compare to:

$ tox -e py3.13-pytest8.3-gherkin_official30
[…]
================================== 138 passed, 1 skipped in 10.87s ===================================

Additional context
N/A

Version

  • pytest version: 8.3
  • pytest-bdd version: master (01c99a6693f9023023fe1c1c7373fa88559c4dec); also observed in 8.1.0
  • OS: Fedora 42, x86_64
Ngôn ngữ chính
Python
Star
1.5k
Fork
251
Merge trung bình
43 phút
Pull request đã merge (30 ngày)
2

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.