简体   繁体   English

使用 Pycharm 调试 python-behave 步骤

[英]Debugging python-behave steps with Pycharm

I'm using Pycharm to write tests and running them with behave.我正在使用 Pycharm 编写测试并使用 behave 运行它们。 I'm running the behave commands with cli.我正在使用 cli 运行行为命令。 To write the features and scenarios i'm using Pycharm. How can i debug each step?要编写功能和场景,我正在使用 Pycharm。如何调试每个步骤?

You need Pycharm Professional to easily setup debuging. 您需要Pycharm Professional来轻松设置debuging。 Just create run/debug configuration , choose behave framework, then specify feature files folder and behave params. 只需创建运行/调试配置 ,选择行为框架,然后指定功能文件文件夹并执行params。

有效配置的屏幕截图

Otherwise, if you doesn't have PyCharm Professional, you can create just basic python configuration, specify module behave and enter path to your feature folders in parameters. 否则,如果您没有PyCharm Professional,则可以创建基本的python配置,指定模块行为并在参数中输入功能文件夹的路径。

有效配置的屏幕截图

If you don't have PyCharm proffesional and you want to launch behave from commands, you can resort to the well-known technique of placing prints with debug information wherever you think necessary to help you solve possible errors.如果你没有 PyCharm proffesional 并且你想从命令启动行为,你可以求助于众所周知的技术,在你认为必要的地方放置带有调试信息的打印件,以帮助你解决可能的错误。

For these prints to be shown in the console, you must launch the behave command with the --no-capture option.要在控制台中显示这些打印,您必须使用--no-capture选项启动 behave 命令。 An example would be:一个例子是:

  • features/test.feature功能/测试功能
Feature: Test

  Scenario: Scenario title
    Given This is one step
  • steps/steps.py步骤/步骤.py
from behave import *


@given("This is one step")
def step_impl(context):
    print("I'm executing this code??")


@given("this is other setp")
def step_impl(context):
    print("or I'm executing this other code??")

  • ouptut of behave --no-capture features/test.feature行为的输出behave --no-capture features/test.feature
$ behave --no-capture features/test.feature
Feature: Test # features/test.feature:1

  Scenario: Scenario title  # features/test.feature:3
    Given This is one step  # steps/steps.py:4
I'm executing this code??

1 feature passed, 0 failed, 0 skipped
1 scenario passed, 0 failed, 0 skipped
1 step passed, 0 failed, 0 skipped, 0 undefined
Took 0m0.000s

As you can see, the print tells you exactly which step you are running.如您所见,打印会准确告诉您正在运行的步骤。 With this technique you can debug your code by printing variable values or viewing the execution flow of your code.使用此技术,您可以通过打印变量值或查看代码的执行流程来调试代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM