I am having the same issue. My paths are often non-standard in my projects. I thought that might be why I'm having this issue. So I did the following to be as simple as possible, and to let PyCharm choose what it wants for me.
I created an empty folder, then created a virtual environment (I use pyenv).
Then I ran pip install pytest-bdd
I opened this folder in PyCharm, set the project interpreter to the one in the virtual environment I created, and confirmed that pytest-bdd
and its dependencies are installed. I have previously installed the JetBrains Gherkin plugin.
I then created a folder named features
in which I added the following:
# some_feature.feature
Feature: Can run executable specifications
As a developer
I want to run a feature and/or scenario from this page
So that I can demonstrate with confidence the system behaves as expected
Scenario: A simple scenario
Given I have a scenario
When I click the play button in this file
Then the step definitions are executed
I then moved my cursor to the Given
clause, hit Alt+Enter, and selected "Create all step definitions". I accepted the defaults when prompted to "Create new step definition file". This created a file named some_feature.py
as a peer to the .feature
file itself (i.e. in the features
folder.
I edited this file to look like this:
# some_feature.py
from pytest_bdd import scenario, given, when, then
@scenario('some_feature.feature', 'A simple scenario')
def test_some_feature():
pass
@given("I have a scenario")
def step_impl():
raise NotImplementedError(u'STEP: Given I have a scenario')
@when("I click the play button in this file")
def step_impl():
raise NotImplementedError(u'STEP: When I click the play button in this file')
@then("the step definitions are executed")
def step_impl():
raise NotImplementedError(u'STEP: Then the step definitions are executed')
Here is what I expected:
test_some_function()
function in the .py
fileFeature:
or beside Scenario:
in the .feature
file. (there is only one scenario so both should do the same in this case)What I see is:
.py
file.feature
file. Instead of the usual context menu in which I can select Run or Debug among other options, I get a context menu with one option only: "Nothing here"What configuration detail am I missing to replace "Nothing here" with the ability to run the tests directly from the features file - as I can from WebStorm, even with exotic/complex paths?