I'm looking for a way to run specific Pytest BDD scenarios from VSCode UI. At the moment the UI can run all scenarios in a class, but not specific scenarios.
Project structure:
tests
|-- features
|--sample_tests.feature
|-- step_defs
|--test_example.py
sample_tests.feature
Feature: Sample tests
Scenario: Test number one
Given I have 100 pounds
Then I have money
@second
Scenario: Test number two
Given I open some page
Then I verify the header is displayed
test_example.py
cwd = os.getcwd()
full_path = f"{cwd}/tests/features/sample_test.feature"
@scenario(full_path, 'Test number one')
def test_method_name():
logger.info("End of the first test")
pass
@given("I have 100 pounds")
def hundred_pounds():
logger.info("Inside I have 100 pounds")
@then("I have money")
def have_money():
logger.info("Inside I have money")
@scenario(full_path, 'Test number two')
def test_first_browser_test():
logger.info("End of the second test")
pass
@given("I open some page")
def open_page(driver):
driver.get("www.google.com")
logger.info("google opened")
@then("I verify the header is displayed")
def verify_page():
logger.info("Second browser step")
On the image below, that's how it works currently:
- Running
test_example_steps
runs both tests - Running
test_method_name
ortest_first_browser_test
doesn't do anything (this is what I'm trying to make work) - Clicking on "Go to Test" on
test_example_steps
takes you totest_example_steps.py
- Clicking on "Go to Test" on
test_method_name
ortest_first_browser_test
takes you to/lib/python3.9/site-packages/pytest_bdd/scenario.py
I tried VSC and Pycharm with the same result. The only way I could run a specific scenario is the command line, e.g. pytest -m "second"
. But how to do it via UI? Expected to be able to run individual tests from IDE UI, as using command line is not my preferred way of running these locally.