小编Ben*_*Ben的帖子

如何在行为中看到print()语句(BDD)

上下文:我使用Python with Behave(BDD).

无论我是从命令行(行为)还是从自定义main()运行我的测试,行为都是相同的:测试运行,我在控制台中看到的唯一输出是标准BDD报告.

我的测试包括帮助我调试代码的print()语句.但是,当我运行时,控制台输出中没有显示这些打印语句.

我们有什么方法可以"行为"在我们的代码中显示print语句吗?

我的主要()

config = Configuration()
if not config.format:
    default_format = config.defaults["default_format"]
    config.format = [ default_format ]
    config.verbose = True
r = runner.Runner(config)
r.run()

if config.show_snippets and r.undefined_steps:
    print_undefined_step_snippets(r.undefined_steps)
Run Code Online (Sandbox Code Playgroud)

我的test.feature文件:

Feature: My test feature with the Behave BDD
    Scenario: A simple test
    Given you are happy
    When someone says hi
    Then you smile
Run Code Online (Sandbox Code Playgroud)

我的test_steps.py文件:

from behave import given, when, then, step, model

@given('you are happy')
def step_impl(context):
    pass

@when ('someone says {s}')
def step_impl(context, s): …
Run Code Online (Sandbox Code Playgroud)

python bdd python-behave

41
推荐指数
4
解决办法
2万
查看次数

Behave 的装饰器是如何创建/声明的?

我目前正在使用 Behave(用于 Python 的 BDD)并且一直在挖掘源代码以了解@given,@when@then装饰器是如何声明的。

我走得最远的是看看step_registry.py我在哪里找到了setup_step_decorators(context=None, registry=registry)似乎在做这项工作的功能。

但是,我不太明白这些装饰器是如何创建的,因为它们似乎没有在源代码中以def when(...):. 我的印象是它们是基于字符串 ( for step_type in ('given', 'when', 'then', 'step'):)列表声明的,然后通过调用make_decorator().

有人可以引导我完成代码并解释这些装饰器的声明位置/方式吗?

您可以在此处访问Behave源代码

python bdd python-decorators python-behave

3
推荐指数
1
解决办法
742
查看次数

标签 统计

bdd ×2

python ×2

python-behave ×2

python-decorators ×1