Debugging python-behave steps with Pycharm
Question:
I’m using Pycharm to write tests and running them with behave. I’m running the behave commands with cli. To write the features and scenarios i’m using Pycharm. How can i debug each step?
Answers:
You need Pycharm Professional to easily setup debuging. Just create run/debug configuration, choose behave framework, then specify feature files folder and behave 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.

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.
For these prints to be shown in the console, you must launch the behave command with the –no-capture option. An example would be:
- features/test.feature
Feature: Test
Scenario: Scenario title
Given This is one step
- steps/steps.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
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.
It is possible to step-by-step debug from the console.
call the function breakpoint()
anywhere you want the test to stop, then launch the tests with --no-capture
flag.
Once the execution reaches the breakpoint you will have a Pdb console ready to receive commands.
I’m using Pycharm to write tests and running them with behave. I’m running the behave commands with cli. To write the features and scenarios i’m using Pycharm. How can i debug each step?
You need Pycharm Professional to easily setup debuging. Just create run/debug configuration, choose behave framework, then specify feature files folder and behave 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.
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.
For these prints to be shown in the console, you must launch the behave command with the –no-capture option. An example would be:
- features/test.feature
Feature: Test
Scenario: Scenario title
Given This is one step
- steps/steps.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
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.
It is possible to step-by-step debug from the console.
call the function breakpoint()
anywhere you want the test to stop, then launch the tests with --no-capture
flag.
Once the execution reaches the breakpoint you will have a Pdb console ready to receive commands.