{"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":"python","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,"search_vec":"'1.3.3':48 'allow':36 'async':34 'async-step':33 'autom':72 'bdd':2,11,68 'behav':1,4 'behavior':8 'behavior-driven':7 'bug':54 'chang':67 'clear':38 'cucumb':30,71 'cucumber-express':29 'current':44 'develop':10 'driven':9 'enabl':15 'enhanc':59 'execut':19 'express':31 'featur':23,58 'file':24 'fix':55 'focus':52 'framework':3,12 'gherkin':22,27,70 'human':40 'human-read':39 'increment':57 'larger':66 'pre':63 'pre-releas':62 'python':14 'readabl':41 'releas':50,64 'sometim':60 'specif':20 'stabl':45 'step':35 'support':26 'team':16 'test':42,69 'typic':51 'v6':28 'version':46 'write':18","created_at":"2026-04-09T18:37:00.879868+00:00","updated_at":"2026-04-16T00:03:05.582810+00:00","problems":[{"fix":"Install the behave library using pip: `pip install behave`.","cause":"The behave library is not installed in the Python environment being used, or the Python interpreter cannot locate the installed package.","error":"ModuleNotFoundError: No module named 'behave'"},{"fix":"Ensure that a Python step definition function exists with a decorator (e.g., `@given('my step text')`) that exactly matches the Gherkin step. Verify that the step definition file is correctly placed within the 'features/steps' directory and that Python package structure (e.g., `__init__.py` files) is correct if using subdirectories.","cause":"A step in your Gherkin feature file does not have a corresponding Python step definition (a function decorated with @given, @when, or @then) in the 'features/steps' directory, or behave cannot locate the step definition file.","error":"Undefined step"},{"fix":"The standard and recommended way to import these decorators is `from behave import given, when, then`. Ensure your `behave` installation is reasonably up-to-date (version 1.2.7 or higher), and if using a linter, configure it to correctly handle behave's imports or suppress the specific error.","cause":"This error can occur if you're trying to import step decorators (like `given`, `when`, `then`) directly from the top-level `behave` package, especially with older behave versions or if a linter (like Pylint) is misconfigured and doesn't recognize these dynamically exposed names.","error":"ImportError: cannot import name 'given' from 'behave'"},{"fix":"Ensure the attribute is correctly set on the `context` object within the appropriate hook (e.g., `context.driver = webdriver.Chrome()` in `features/environment.py` within `before_scenario` or `before_feature`) and that the attribute name is consistent when being accessed.","cause":"You are attempting to access an attribute (like 'driver' for a Selenium WebDriver instance) on the behave 'context' object that has not been previously set or is not available within the current scope (e.g., a specific step or hook).","error":"AttributeError: 'Context' object has no attribute 'driver'"},{"fix":"Organize your project structure according to behave's conventions: place your feature files in a 'features' directory (e.g., `your_project/features/my_feature.feature`) and your step definitions in a 'steps' subdirectory within 'features' (e.g., `your_project/features/steps/my_steps.py`). If running behave from a different directory, you might need to specify the path explicitly.","cause":"Behave cannot find the required 'features' directory or the 'steps' subdirectory within it, which is where your feature files and step definitions are expected to reside by default.","error":"ConfigError: No steps directory in []"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.3.3","cli_name":"behave","cli_version":"behave 1.3.3","type":"library","homepage":null,"github":"https://github.com/behave/behave","docs":"https://behave.readthedocs.io/en/latest/","changelog":"https://github.com/behave/behave/blob/main/CHANGES.rst","pypi":"https://pypi.org/project/behave/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}