Pytest BDD - select stubbed or live API calls

258 views Asked by At

I'm working on developing some Behavior Driven Development i.e style tests using pytest-bdd. We want to re-use the same features and more or less the same step definitions to having both stubbed and live calls to a third party API i.e. we want to reuse test code for integration and end to end testing.

I'm wondering about whether there was a convention on how to handle alternating between mocked and real calls in pytest_bdd or pytest

This question is similar: Running pytest tests against multiple backends? with an answer to add a parser option with a pytest_addoption hook placed in the top level conftest.py.

1

There are 1 answers

0
radlab On

It looks like a good approach to select a stubbed or live api call in api is to add a parser option with a pytest_addoption hook. Conditional logic will need to look for those option in the relevant tests.

This answer to a similar question is the source for this approach and has more detail: https://stackoverflow.com/a/50686439/961659