0

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.

radlab
  • 53
  • 9
  • What is wrong with the answer you have linked? – hoefling Apr 27 '21 at 08:19
  • Technically I saw nothing wrong with that approach. However, this was a single answer to the question so I'm still seeking more feedback as to whether this is a preferred style in pytest. – radlab Apr 27 '21 at 14:39
  • I'd say yes it is, also the answer comes from a `pytest` dev, a more reliable source is hardly imaginable. – hoefling Apr 28 '21 at 07:22
  • @joefling thanks for the tip, I hadn't see the author's bio. – radlab Apr 28 '21 at 19:17

1 Answers1

0

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

radlab
  • 53
  • 9