Background I need to run some specific method after a scenario run for a specific test scenario
What I tried
Scenario is as below
Scenario: Test Fixture
Given I am a mechanic
When I start a car
Then I should get to know the primitive issues
Step definition looked as below
@pytest.mark.usefixtures("stop_car")
@scenario('../FeatureFiles/Test.feature', 'Test Fixture')
def test_mechanic():
logging.info('Test Mechanic')
@given("I am a mechanic")
def given_mechanic():
print('given_mechanic')
@when("I start a car")
def when_mechanic():
print('when_mechanic')
@then("I should get to know the primitive issues")
def then_mechanic():
print('then_mechanic')
assert 1 < 0, 'Failed validation'
@pytest.fixture
def stop_car():
print('stop car')
Issue Faced
The problem here is the 'stop_car()' function is triggered before the execution of the scenario. I need to run at the end of the scenario. Even if any assertion failed in Given, When or Then the method 'stop_car()' should be executed in any case