Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Regression: Descriptions consisting of just a comment in a Scenario or Scenario Outline block throws error #373

Open
jsa34 opened this issue Feb 16, 2025 · 0 comments
Labels
🐛 bug Defect / Bug

Comments

@jsa34
Copy link
Contributor

jsa34 commented Feb 16, 2025

👓 What did you see?

This commit: #334
Appears to have broken a number of unit tests for pytest-bdd due to the gherkin parser throwing errors on parsing feature files.
The cause is that the parser throws an error if the description if just a comment inside a Scenario or Scenario Outline. It appears this was a missed test case scenario in the PR.

See CI job https://github.com/pytest-dev/pytest-bdd/actions/runs/13252365760/job/36993581825?pr=765 for errors.

Backtrace example:

test_scenario_comments.py:5: in <module>
    @scenario("comments.feature", "Comments")
/pytest-bdd/src/pytest_bdd/parser.py:480: in parse
    gherkin_doc: GherkinDocument = self._parse_feature_file()
/pytest-bdd/src/pytest_bdd/parser.py:476: in _parse_feature_file
    return get_gherkin_document(self.abs_filename, self.encoding)
/pytest-bdd/src/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:96: in parse
    state = self.match_token(state, token, context)
/.venv/lib/python3.10/site-packages/gherkin/parser.py:231: in match_token
    return state_map[state](token, context)
/.venv/lib/python3.10/site-packages/gherkin/parser.py:795: in match_token_at_11
    self.end_rule(context, 'Description')
/.venv/lib/python3.10/site-packages/gherkin/parser.py:120: in end_rule
    self.handle_ast_error(context, rule_type, self.ast_builder.end_rule)
/.venv/lib/python3.10/site-packages/gherkin/parser.py:2800: in handle_ast_error
    self.handle_external_error(context, True, argument, action)
/.venv/lib/python3.10/site-packages/gherkin/parser.py:2813: in handle_external_error
    return action(argument)
/.venv/lib/python3.10/site-packages/gherkin/ast_builder.py:54: in end_rule
    self.current_node.add(node.rule_type, self.transform_node(node))
/.venv/lib/python3.10/site-packages/gherkin/ast_builder.py:272: in transform_node
    last_non_empty = next(
E   StopIteration

Feature file examples:

Feature: Comments
  Scenario: Comments
    # Comment
    Given I have a bar
Feature: Outline Test

  Scenario Outline: Outline example
    # Just print the string so that we can assert later what it was by reading the output
    Given I print the <string>

    Examples:
      | string       |
      | bork         |

✅ What did you expect to see?

No errors with comments in Scenarios or Scenario Outlines!

📦 Which tool/library version are you using?

[email protected]

🔬 How could we reproduce it?

  1. Create a feature file with a comment inside the scenario, starting with a '#' char (pythonic comment syntax)
  2. Parse the feature file using: Parser().parse(feature_file_text)

📚 Any additional context?

No response

@jsa34 jsa34 added the 🐛 bug Defect / Bug label Feb 16, 2025
@jsa34 jsa34 changed the title [Python] Regression: Comments inside Scenario or Scenario Outline block throws error [Python] Regression: Descriptions consisting of just a comment Scenario or Scenario Outline block throws error Feb 16, 2025
@jsa34 jsa34 changed the title [Python] Regression: Descriptions consisting of just a comment Scenario or Scenario Outline block throws error [Python] Regression: Descriptions consisting of just a comment in a Scenario or Scenario Outline block throws error Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

1 participant