-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Allow to dynamically create fixture in plugin #12376
Copy link
Copy link
Open
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
Metadata
Metadata
Assignees
Labels
topic: fixturesanything involving fixtures directly or indirectlyanything involving fixtures directly or indirectlytype: proposalproposal for a new feature, often to gather opinions or design the API around the new featureproposal for a new feature, often to gather opinions or design the API around the new feature
What's the problem this feature will solve?
I am the author of next-actions/pytest-mh which is a multihost testing plugin for pytest. We are doing some black magic to dynamically create test fixtures and map them to some custom objects. Some user-focused details are described here but TLDR we are doing this:
In this scenario,
clientandldapare passed to the test_example by setting it initem.funcargsin runtest hook to internal objects created per-tests.pytest_fixtureis standard pytest fixture. This works nicely and it is using only public fields (I'm not sure if funcargs is documented, but at the very least it is not prefix with_).However, accessing these data from pytest fixture fails, obviously:
... because
clientis not a registered fixture. I probably could manage that by accessing pytest private stuff, but I'd like to avoid that.I would like to be able to create and delete fixture (at least function-scoped) inside hooks.
Describe the solution you'd like
Provide API to dynamically register and unregister fixtures from pytest hooks.
Alternative Solutions
Currently, deep and private pytest objects and attributes are required.
Additional context