
- Behave Tutorial
- Behave - Home
- Behave - Introduction
- Behave - Installation
- Behave - Command Line
- Behave - Configuration Files
- Behave - Feature Testing Setup
- Behave - Gherkin Keywords
- Behave - Feature Files
- Behave - Step Implementations
- Behave - First Steps
- Behave - Supported Languages
- Behave - Step Parameters
- Behave - Scenario Outlines
- Behave - Multiline Text
- Behave - Setup Table
- Behave - Steps in a Step
- Behave - Background
- Behave - Data Types
- Behave - Tags
- Behave - Enumeration
- Behave - Step Matchers
- Behave - Regular Expressions
- Behave - Optional Part
- Behave - Multi-Methods
- Behave - Step Functions
- Behave - Step Parameters
- Behave - Runner Script
- Behave - Exclude Tests
- Behave - Retry Mechanism
- Behave - Reports
- Behave - Hooks
- Behave - Debugging
- Behave Useful Resources
- Behave - Quick Guide
- Behave - Useful Resources
- Behave - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Behave - Runner Script
We can run a Behave test, by running the command line arguments, or we can create a runner script. This script gives the provision of running the test and generating the corresponding report.
We can do a re-try and execute the failed test. Also, before executing the entire suite, the runner script is capable of making an application programming interface (API) call and ensuring that there are no issues with the API.
Steps for Runner Script
Follow the steps given below to create and execute a runner script successfully in Behave.
Step 1 − Create a runner script (runner.py) within the features folder.
The following screen will appear on your computer −

Step 2 − Runner Script Implementation to run tests
The runner script can be implemented to run the tests by using the below mentioned code −
import subprocess if __name__ == '__main__': #command line args along with error capture on failure with check true s = subprocess.run('behave --no-capture',shell=True, check=True)
Step 3 − Execute the runner script
Execute runner.py file with command python3 runner.py (if Python version is 3). The following screen will appear on your computer:

Step 4 − Parametrise runner script by passing command line arguments.
The runner script implementation to run tests can be done as follows −
import argparse import subprocess if __name__ == '__main__': p = argparse.ArgumentParser() #--testdir command line argument added p.add_argument('--testdir', required=False, help="File path") a = p.parse_args() testdir = a.testdir #complete command c= f'behave --no-capture {testdir}' s = subprocess.run(c, shell=True, check=True)
Step 5 − Execute the runner script
Execute runner.py file with command python3 runner.py --testdir=features.
