pytest-dev / pytest-dev/pytest-bdd
test_step_outside_scenario_or_background_error fails with current gherkin-official
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 251
- Avg merge
- 43m
- Merged PRs (30d)
- 2
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/parser/test_errors.py and run the tox environments py3.13-pytest8.3-gherkin_officiallatest and py3.13-pytest8.3-gherkin_official30 to compare the failure. Investigate how the current gherkin-official version handles the step outside a Scenario or Background, and finish when the test reports the expected FeatureError with the latest dependency while the parser tests pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100