1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to run a specific function at the end of a specific scenario test in pytest BDD...

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    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

    Continue reading...

Compartilhe esta Página