<p><strong>过时的答案,</strong>
当前支持自身,如本<a href="https://stackoverflow.com/a/28638924/538284">answer</a>所述。</p>
<p>不,这是不可能的,因为在<code>configuration.py</code>文件中有一个<code>parser</code>就是<a href="https://github.com/behave/behave/blob/77ebf779452a826601f21629f4351027f3639dda/behave/configuration.py#L421" rel="nofollow noreferrer">defined</a>,并且只有<a href="https://github.com/behave/behave/blob/77ebf779452a826601f21629f4351027f3639dda/behave/configuration.py#L492" rel="nofollow noreferrer">allow</a>定义了<a href="https://github.com/behave/behave/blob/77ebf779452a826601f21629f4351027f3639dda/behave/configuration.py#L56" rel="nofollow noreferrer">options</a>。</p>
<p>但如果你想你可以(通过猴子补丁的帮助!),只需将与其他选项相同的选项添加到此<code>parser</code>。</p>
<p>为此,首先创建一个文件,例如<code>behave_run.py</code>,并在运行<code>behave</code>之前修补这个<code>parser</code>:</p>
<pre><code>from behave import configuration
from behave import __main__
# Adding my wanted option to parser.
configuration.parser.add_argument('-u', '--url', help="Address of your url")
# command that run behave.
__main__.main()
</code></pre>
<p>现在如果运行<code>python behave_run.py --help</code>,您可以看到新的<code>url</code>选项:</p>
<pre><code>$ python behave_run.py --help | grep url
-u URL, --url URL Address of your url
</code></pre>
<p>现在,您可以运行这个<code>behave_run.py</code>文件,比如<code>behave</code>文件,并传递您的url参数:</p>
<pre><code>$ python behave_run.py --url http://google.com
</code></pre>
<p>您可以使用<code>context.config.url</code>访问<code>url</code>选项的值,例如在<code>environment.py</code>文件中,然后将其设置为在其他函数中使用:</p>
<pre><code>def before_all(context):
context.browser = webdriver.Firefox()
context.url = context.config.url
</code></pre>
<p><em>注意:</em></p>
<p>如果要从任何位置将<code>python run_behave.py</code>调用为<code>run_behave.py</code>,请添加以下行:</p>
<p><code>#!/usr/bin/env python</code></p>
<p>到<code>run_behave.py</code>的第一行,并使用<code>chmod +x run_behave.py</code>将其模式更改为可执行文件,然后将此文件复制到<code>PATH</code>的一个位置,例如使用<code>sudo mv run_behave.py /usr/local/bin/run_behave.py</code>在<code>/usr/local/bin</code>中</p>