使用 PyCharm CE 调试步骤文件中的行为上下文
我正在尝试使用 PyCharm CE 调试行为步骤文件。
按照此 帖子 上的说明,我成功运行了测试。
的示例
Feature: testing behave and pandas
Scenario: run a simple test
Given a pandas dataframe
When we check the number of columns
Then the number of columns is 2
这是功能文件和步骤文件
from behave import *
import pandas as pd
@given("a pandas dataframe")
def given_dataframe(context):
context.df = pd.DataFrame(
{"col1": [1, 2], "col2": [3, 4]}
)
@when("we check the number of columns")
def when_check_dataframe(context):
context.num_col = len(context.df.columns)
@then("the number of columns is 2")
def then_num_col(context):
assert context.num_col == 2
:此测试有效,但例如,如果我在 when
步骤中放置断点并检查 context
的内容没有获得任何值:
Feature: testing behave and pandas # tutorial.feature:1
Scenario: run a simple test # tutorial.feature:3
Given a pandas dataframe # steps/tutorial.py:5
When we check the number of columns # steps/tutorial.py:12
>>> context
>>> context.df
>>> context.df.columns
>>>
就像调试器无法打印出任何变量
有人知道吗? 我必须在 behave.ini
中添加一些内容吗?
不幸的是我无法升级到专业版。
更新
我设法使用记录器打印出来:
import logging
logger = logging.getLogger()
logger.info(context)
但这并不是很方便...... 如果有的话我会更喜欢另一种方法。
I am trying to debug a behave step file using PyCharm CE.
Following the instruction on this post I managed to run my test.
This is an example of feature file:
Feature: testing behave and pandas
Scenario: run a simple test
Given a pandas dataframe
When we check the number of columns
Then the number of columns is 2
and step file:
from behave import *
import pandas as pd
@given("a pandas dataframe")
def given_dataframe(context):
context.df = pd.DataFrame(
{"col1": [1, 2], "col2": [3, 4]}
)
@when("we check the number of columns")
def when_check_dataframe(context):
context.num_col = len(context.df.columns)
@then("the number of columns is 2")
def then_num_col(context):
assert context.num_col == 2
This test works but if, for example, I put a breakpoint in the when
step and check the content of context
I don't obtain any value:
Feature: testing behave and pandas # tutorial.feature:1
Scenario: run a simple test # tutorial.feature:3
Given a pandas dataframe # steps/tutorial.py:5
When we check the number of columns # steps/tutorial.py:12
>>> context
>>> context.df
>>> context.df.columns
>>>
It's like the debugger can't print out any variable
Does anyone have any idea?
Do I have to add something in the behave.ini
?
Unfortunately I can't move to the Pro version.
Update
I managed to print out using a logger:
import logging
logger = logging.getLogger()
logger.info(context)
but it's not really convenient...
If there is I would prefer another method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论