You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅通过Feature名称运行Behave的多个Feature文件?

Run Multiple Behave Features Without Full Paths

Got it, let's sort this out so you can run multiple feature files without typing those tedious full paths every time! Here are a few practical, easy-to-implement solutions:

1. Use Behave's Default Feature Directory

Behave automatically looks for feature files in a directory named features/ (in your current working directory) by default. If you organize your feature files here, you can run them directly by name:

  • To run specific feature files with their .feature extension:
    behave feature_name_1.feature feature_name_2.feature
    
  • If there’s no risk of name conflicts (no other files with the same name in the directory), you can even omit the .feature extension:
    behave feature_name_1 feature_name_2
    

2. Set the BEHAVE_FEATURES Environment Variable

If your feature files are stored in a different directory (not the default features/), you can point Behave to that directory permanently using an environment variable:

For Linux/macOS (bash/zsh):

export BEHAVE_FEATURES="/absolute/path/to/your/feature/directory"

Add this line to your ~/.bashrc or ~/.zshrc to make it persist across terminal sessions.

For Windows (Command Prompt):

set BEHAVE_FEATURES=C:\absolute\path\to\your\feature\directory

To make this permanent, add the variable via System Properties → Environment Variables.

For Windows (PowerShell):

$env:BEHAVE_FEATURES = "C:\absolute\path\to\your\feature\directory"

Add this to your PowerShell profile to keep it persistent.

Once set, you can run multiple features from anywhere using just their names:

behave feature_name_1 feature_name_2

3. Specify the Feature Directory in the Command

If you don’t want to set an environment variable, you can explicitly tell Behave where to look for features using the --features flag, followed by the directory path and your feature names:

behave --features /path/to/your/features feature_name_1.feature feature_name_2.feature

4. Create a Simple Script (For Repeated Runs)

If you regularly run the same set of features, save yourself the hassle by creating a small script:

Linux/macOS (Shell Script):

Create a file named run_my_features.sh:

#!/bin/bash
behave /full/path/to/feature_name_1.feature /full/path/to/feature_name_2.feature

Make it executable with chmod +x run_my_features.sh, then run it anytime with:

./run_my_features.sh

Windows (Batch Script):

Create a file named run_my_features.bat:

@echo off
behave C:\full\path\to\feature_name_1.feature C:\full\path\to\feature_name_2.feature

Double-click the file or run it from Command Prompt.

内容的提问来源于stack exchange,提问作者Iwona

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 19:29:06