[Python] How to pass in string parameter in python-bdd test

Discussão em 'Python' iniciado por Stack, Novembro 30, 2024.

  1. Stack

    Stack Membro Participativo

    I am trying to write a very simple test using pytest and pytest-bdd. The test runs OK if none of the step definitions have any parameters. However, I cannot seem to get to work the simple passing in of a single string parameter.

    Here is my step:

    Given the current account balance is "zero"


    Here is the step definition:

    @given("the current account balance is {arg}")
    def current_account_initial_balance(amount):
    print(amount)


    When I run the test, then this is the output (somewhat edited for clarity):

    ============================================================= test session starts ==============================================================
    platform win32 -- Python 3.11.5, pytest-8.3.3, pluggy-1.5.0rootdir: C:\pythonplugins: bdd-8.0.0
    collected 1 item

    TestBankTransactions.py F

    =========================================================== short test summary info ============================================================
    FAILED TestBankTransactions.py::test_deposit_into_account - pytest_bdd.exceptions.StepDefinitionNotFoundError: Step definition is not found: Given "the current account balance is "zero"". Line 6 in sc...
    ============================================================== 1 failed in 0.02s ===============================================================


    I have tried all sorts of googling and different combinations of "' and "" but nothing has worked.

    Continue reading...

Compartilhe esta Página