pytest-dev / pytest-bdd

BDD library for the py.test runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.3k stars 219 forks source link

pytest-bdd needs to support OOP based test frameworks #632

Closed olek93 closed 1 year ago

olek93 commented 1 year ago

Hi, I am trying to integrate my pytest framework which uses BaseSuite class and test classes with pytest-bdd. Unfortunately, pytest-bdd focuses too much on fixtures. There is no way to define step definitions inside my test classes which access a lot of things through self and I find it a really good practice... I use BaseSuite with setup_class, teardown_class, setup_method and teardown_method, I have my own method performing assertions which is reused and do a lot of other things beside just asserting. I don't see any point in making a fixture for setups and teardowns and assigning all stuff to pytest object - which is dynamically created and IDEs cannot know what it has etc... I mean, pytest-bdd forces users to use fixture based frameworking only which many developers may find restricting. Do You plan to add support for OOP based frameworks? Thanks

The-Compiler commented 1 year ago

pytest-bdd is a pytest plugin, and as such will follow central pytest concepts. What do you mean by "assigning all stuff to pytest object - which is dynamically created and IDEs cannot know what it has etc..."?

olek93 commented 1 year ago

I meannit is possible to use fixtures for everything. Like for example saving test config somewhere, return in etc. But if I need to save some data to be reused later in different test or fixture I can assign this value to pytest, and then use it. It's OK, but since it's dynamically adding values i don't have a definition of what can be contained by pytest.

I am trying to say many devs will use class based frameworks using pytest since it supports it and it's not nice that bdd can be used only using fixture cascade frameworks. I will probably try to fork out and add this support

youtux commented 1 year ago

As @The-Compiler said, pytest-bdd plugs into pytest and uses its infrastructure (fixtures and hooks) to execute Gherkin files. If you prefer not to utilize pytest and pytest-bdd, you may want to consider utilizing the behave test runner.

The-Compiler commented 1 year ago

But if I need to save some data to be reused later in different test or fixture I can assign this value to pytest, and then use it. It's OK, but since it's dynamically adding values i don't have a definition of what can be contained by pytest.

I'd probably use a fixture with a different scope for things like that instead.