{"id":1948,"library":"behave","title":"behave (BDD Framework)","description":"behave is a behavior-driven development (BDD) framework for Python, enabling teams to write executable specifications in Gherkin feature files. It supports Gherkin v6, Cucumber-Expressions, and async-steps, allowing for clear, human-readable tests. The current stable version is 1.3.3, with releases typically focusing on bug fixes and incremental feature enhancements, sometimes with pre-releases for larger changes.","status":"active","version":"1.3.3","language":"en","source_language":"en","source_url":"https://github.com/behave/behave","tags":["bdd","testing","gherkin","cucumber","automation"],"install":[{"cmd":"pip install behave","lang":"bash","label":"Install behave"}],"dependencies":[],"imports":[{"note":"Standard decorators for defining steps in Python step definitions.","symbol":"given, when, then","correct":"from behave import given, when, then"},{"note":"A generic step decorator for defining steps without specific 'Given', 'When', 'Then' keywords.","symbol":"step","correct":"from behave import step"},{"note":"Hook functions (e.g., `before_feature`, `after_step`) are typically defined in `environment.py` and automatically discovered. Specific imports like `async_run_called_with_context` are for advanced async step handling, not general use.","wrong":"from behave.api.async_step import async_run_called_with_context","symbol":"before_all, after_all, before_scenario, after_scenario, etc.","correct":"from behave import * # in environment.py (common practice, but specific imports are also fine)"},{"note":"Used to explicitly set the step matcher (e.g., 're' for regex, 'parse' for parsing, 'cfparse' for composite, 'cucumber_expressions').","symbol":"use_step_matcher","correct":"from behave import use_step_matcher"}],"quickstart":{"code":"# Create the following file structure in your project root:\n#\n# ./\n# ├── features/\n# │   ├── example.feature\n# │   └── steps/\n# │       └── example_steps.py\n# └── (run 'behave' from this root directory)\n\n# --- features/example.feature ---\n# Feature: Basic addition\n#   As a calculator user\n#   I want to be able to add numbers\n#   So that I can get the sum\n#\n#   Scenario: Add two numbers\n#     Given I have the numbers 5 and 3\n#     When I add them\n#     Then the result should be 8\n\n# --- features/steps/example_steps.py ---\nfrom behave import given, when, then\n\n@given('I have the numbers {num1:d} and {num2:d}')\ndef step_impl(context, num1, num2):\n    context.num1 = num1\n    context.num2 = num2\n\n@when('I add them')\ndef step_impl(context):\n    context.result = context.num1 + context.num2\n\n@then('the result should be {expected_result:d}')\ndef step_impl(context, expected_result):\n    assert context.result == expected_result\n\n# To run this example:\n# 1. Create the files as shown above.\n# 2. Navigate to your project's root directory (containing the 'features' folder) in your terminal.\n# 3. Execute the behave command:\n#    $ behave","lang":"python","description":"This quickstart demonstrates how to create a simple feature file and corresponding step definitions using behave. It covers defining Gherkin steps with parameter parsing and basic assertions. Organize your files as shown, then run `behave` from the project root."},"warnings":[{"fix":"If you relied on nested `steps` directories, you must explicitly enable `recursive_steps_import` in your configuration (e.g., `behave.ini`). The recommended best practice is to put Python packages or step-libraries on the Python search path, not directly in nested `steps` directories, to avoid relative import issues.","message":"Recursive discovery and import of steps directories is disabled by default starting from v1.3.2. Nested `steps` directories under the primary `steps` directory will no longer be automatically scanned.","severity":"breaking","affected_versions":">=1.3.2"},{"fix":"If you are using Python 2.7, ensure you upgrade to `v1.3.3` or later to restore compatibility. Users on Python 3.x were unaffected.","message":"Python 2.7 support was temporarily broken in `v1.3.2` due to an oversight.","severity":"gotcha","affected_versions":"1.3.2"},{"fix":"This issue was fixed in `v1.3.1` (although the changelog mentions it for 1.3.1 and 1.3.0). Ensure you are on `v1.3.1` or later if you encounter this when using Python 3.6, especially with async features.","message":"ImportError for `asynccontextmanager` in Python 3.6 could occur with `v1.3.0` and `v1.3.1`.","severity":"gotcha","affected_versions":"1.3.0, 1.3.1"},{"fix":"While these are powerful new features, migrating older projects to leverage them might require updating Gherkin syntax or step definitions. Old Gherkin syntax and 'parse'/'re' matchers generally remain compatible, but for new features, new syntax and step matchers (like `use_step_matcher('cucumber_expressions')`) will be required.","message":"Version 1.3.0 introduced Gherkin v6, native Cucumber-Expressions, and native async-steps support.","severity":"breaking","affected_versions":">=1.3.0"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}