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.
pip install behaveVerified import paths — ran on the pinned version, not inferred.
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.
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.
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.
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.
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.Install the behave library using pip: `pip install behave`.
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.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.
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.
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.
No dependency data recorded yet.