pytest-dev / pytest-bdd

BDD library for the pytest runner
https://pytest-bdd.readthedocs.io/en/latest/
MIT License
1.32k stars 221 forks source link

Don't make steps fixtures #509

Closed therve closed 2 years ago

therve commented 2 years ago

This is an attempt at removing how steps are registered via fixtures, and instead use a custom registry. It seems that using fixtures for that is a bit awkward, as we can't differentiate steps from regular fixtures apart from the parser attribute, and we need to access private pytest attributes to do so. Given that pytest_bdd both produces and consumes the steps, it would seem that we can remove it. As an added bonus it should have a minor performance increase.

This is mostly a proof of concept, as I wanted to start the discussion. Let me know if it doesn't make sense, thanks.

youtux commented 2 years ago

I like the idea, but I wonder if that works with how fixtures are expected to be overridden by each module. I wonder if we even have a test for that, but in any case we should support that.

In the doc we only mention that steps defined by the parent packages can be used by the children packages (https://pytest-bdd.readthedocs.io/en/latest/#reusing-steps). But if a step is defined by a child package, it should stay within the scope of that package, and not be available to parent packages.

Does it make sense to you what I mean?

therve commented 2 years ago

Ah that makes sense. I never used that but it would seem that this change breaks this capability, and customizing the registry would make things too complicated and duplicate fixture purposes. I'll think of other smaller changes, thanks!