Skip to content

feat: native pytest-bdd support#484

Merged
gibiw merged 30 commits into
mainfrom
feat/pytest-bdd-support
May 12, 2026
Merged

feat: native pytest-bdd support#484
gibiw merged 30 commits into
mainfrom
feat/pytest-bdd-support

Conversation

@gibiw

@gibiw gibiw commented May 12, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds automatic Gherkin step capture for pytest-bdd scenarios in qase-pytest — no manual qase.step() instrumentation required
  • Preserves Given/When/Then semantics, scenario hierarchy, DataTable/DocString contents, Scenario Outline parameters
  • Tag-based metadata on scenarios: @qase.id=, @qase.suite=, @qase.severity=, @qase.priority=, @qase.layer=, @qase.ignore, @qase.muted, @qase.project_id.CODE=
  • Nested qase.step() inside a step function attaches as a child of the Gherkin step (parent_id hierarchy)
  • Zero changes to qase-python-commons; pytest-bdd>=7.0,<9.0 is a testing extra, not a runtime dependency

Architecture

  • New module qase.pytest.bdd (QasePytestBddPlugin) registered conditionally in conftest.py only when pytest_bdd is importable
  • Bridges six pytest-bdd hooks (before/after_scenario, before/after_step, step_error, step_func_lookup_error) to existing Runtime.add_step() / finish_step() and Result field mutations
  • Pure helpers: parse_scenario_tags, format_data_table, format_docstring, build_step, enrich_result_from_scenario

Test plan

  • Unit tests for tag parser, data-table / docstring formatters, step builder, result enrichment (56 tests in test_bdd_helpers.py)
  • Plugin unit tests with mocked hooks (test_bdd_plugin.py — covers all 6 hooks including happy path, failure path, lookup error, skipped tail, ignore flag)
  • Pytester-based integration tests (10 scenarios: basic, failing tail, lookup error, nested qase.step(), scenario outline, DataTable + DocString, tags, ignore, coexistence with plain pytest)
  • Manual run of examples/single/pytest-bdd/ against local report driver — JSON output verified end-to-end
  • Full qase-pytest suite: 100 passed
  • Manual run against a real Qase TestOps project — pending before merge

Known limitations / follow-ups

  • The local report driver in qase-python-commons flattens StepGherkinData into StepTextData (action="<Keyword> <name>", input_data=table/docstring). TestOps API mode preserves native Gherkin structure; this only affects JSON-report inspection. Worth a separate PR in commons if rich JSON Gherkin shape is desired.
  • pytest-bdd 8.x packs Scenario Outline parameters as a single _pytest_bdd_example argument with a serialized dict. Individual columns (a, b, c) are not split — works correctly but the parameter name is opaque. Possible enhancement: parse and re-expose as separate Qase params.

Customer reproduction

examples/single/pytest-bdd/ reproduces the customer scenario from the original feature request — login.feature with 3 Gherkin steps, each containing a nested qase.step(). Run pytest -v from that directory and inspect build/qase-report/results/*.json to see the full hierarchy.

gibiw added 30 commits May 12, 2026 13:59
@gibiw gibiw merged commit 45e77bf into main May 12, 2026
37 checks passed
@gibiw gibiw deleted the feat/pytest-bdd-support branch May 12, 2026 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant