上下文:我使用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-behave进行BDD测试,我必须从命令行传递一个URL(例如www.abc.com).
$behave -u "www.abc.com"
Run Code Online (Sandbox Code Playgroud)
为了实现这一点,我已阅读了行为文档,但没有足够的材料以及为设置behave.ini文件而给出的解释.我也不确定behave.ini文件如何帮助我传递参数.
有人可以告诉我如何设置命令行参数的行为?
我创建了一个Django应用程序,并且非常依赖于pytest发现和组织我的单元和功能测试.但是,我希望将Behavior Driven with behaveDevelopment应用于将来的测试.遗憾的是,behave测试功能未被自动检测到pytest.
我如何将behave其测试集成到pytest发现,执行和报告中?
我们最近开始使用Behave(github链接)用于新的python Web服务的BDD.
有什么方法可以在测试失败时获得有关失败原因的详细信息吗?他们扔了AssertionError,但他们从来没有表明究竟出了什么问题.例如,期望值和进入断言的实际值.
我们一直试图找到这样的现有功能,但我想它不存在.当然,这个问题的一个很好的答案是关于如何通过修改源代码来实现这种行为的提示和技巧,以及这个特性是否存在于其他类似的BDD框架中,如jBehave,NBehave或Cucumber?
今天,当测试失败时,输出结果如下:
Scenario: Logout when not logged in # features\logout.feature:6
Given I am not logged in # features\steps\logout.py:5
When I log out # features\steps\logout.py:12
Then the response status should be 401 # features\steps\login.py:18
Traceback (most recent call last):
File "C:\pro\venv\lib\site-packages\behave\model.py", line 1037, in run
match.run(runner.context)
File "C:\pro\venv\lib\site-packages\behave\model.py", line 1430, in run
self.func(context, *args, **kwargs)
File "features\steps\login.py", line 20, in step_impl
assert context.response.status == int(status)
AssertionError
Captured stdout:
api.new_session
api.delete_session
Captured logging: …Run Code Online (Sandbox Code Playgroud) 我没有看到这个具体问题的答案(行为测试框架的测试覆盖率工具),我还没有看到任何谷歌搜索结果产生足够的答案.因此...
如何从Behave获取代码覆盖率报告?我发现很难相信没有使用BDD方法的Python开发人员,我发现更难以相信那些使用BDD的Python开发人员在没有功能测试的代码覆盖统计数据的情况下这样做.可以使用Coverage.py来驱动Behave以产生代码覆盖吗?怎么样?
我正在尝试使用 pip install 安装行为并行。我以前使用 pip 安装了程序,所以我知道我的 Python/脚本路径在我的 env 变量中是正确的。但是我看到以下错误
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\.....Temp\\pip-install-rjiorrn7\\behave-parallel\\setup.py'
Run Code Online (Sandbox Code Playgroud)
我该如何解决这个问题
C:\Users\.....>pip install behave-parallel
Collecting behave-parallel
Using cached https://files.pythonhosted.org/packages/05/9d/22f74dd77bc4fa85d391564a232c49b4e99cfdeac7bfdee8151ea4606632/behave-parallel-1.2.4a1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\.........\python\lib\tokenize.py", line 447, in open
buffer = _builtin_open(filename, 'rb')
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\.........\\AppData\\Local\\Temp\\pip-install-7vgf8_mu\\behave-parallel\\setup.py'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\.........\AppData\Local\Temp\pip-install-7vgf8_mu\behave-parallel\
Run Code Online (Sandbox Code Playgroud) 在 selenium 自动化的可视化代码中使用行为框架运行 Python 代码时
日志是:
DevTools 侦听 ws://127.0.0.1:57159/devtools/browser/4787574a-1842-48dd-a69e-919739ddf21a [14332:16524:1120/113508.444:event.imple1444_811imple.444_81008.444_81log13_444_810.0.0.0.444_810.0.0.0.444_8.0.0.0.1.444_810.0.0.0.1.444_1842-48dd-a69e-919739ddf21a ] USB:usb_device_handle_win.cc:1020 无法从节点连接读取描述符:连接到系统的设备未运行。(0x1F) [14332:16524:1120/113508.446:ERROR:device_event_log_impl.cc(211)] [11:35:08.447] USB: usb_device_handle_win.cc:1020 无法从节点连接读取描述符:一个设备连接到系统不运作。(0x1F) [14332:16524:1120/113508.478:ERROR:device_event_log_impl.cc(211)] [11:35:08.478] USB: usb_device_handle_win.cc:1020 无法从系统连接中读取描述符:设备连接到系统不运作。(0x1F) [6492:11676:1120/113533.910:ERROR:ssl_client_socket_impl.cc(960)] 握手失败;返回 -1,SSL 错误代码 1,net_error -113 [6492:11676:1120/113533.998:ERROR:ssl_client_socket_impl.cc(960)] 握手失败;返回 -1,SSL 错误代码 1,net_error -113
python selenium-chromedriver selenium-webdriver python-behave visual-studio-code
有没有办法告诉步骤实现中的行为跳过当前步骤?
就像是:
@given("bla bla bla")
def step():
skip_current_step()
Run Code Online (Sandbox Code Playgroud)
用例是我想检查是否安装了一些其他软件.如果没有,我希望跳过完整的场景.
我一直在考虑从鼻子切换到测试行为(摩卡/柴等等已经破坏了我).到目前为止一直很好,但我似乎无法找出除例外测试异常的方法:
@then("It throws a KeyError exception")
def step_impl(context):
try:
konfigure.load_env_mapping("baz", context.configs)
except KeyError, e:
assert (e.message == "No baz configuration found")
Run Code Online (Sandbox Code Playgroud)
用鼻子我可以用一个注释来测试
@raises(KeyError)
Run Code Online (Sandbox Code Playgroud)
我在行为中找不到这样的东西(不在源中,不在示例中,不在此处).能够指定可能在场景轮廓中抛出的异常肯定会很棒.
有人走过这条路吗?
python-behave ×10
python ×9
bdd ×7
coverage.py ×1
cucumber ×1
jbehave ×1
nbehave ×1
nose ×1
nosetests ×1
pytest ×1