Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Major] Improve the fixture union engine to support hybrid param+fixture mode #170

Open
smarie opened this issue Dec 16, 2020 · 2 comments

Comments

@smarie
Copy link
Owner

smarie commented Dec 16, 2020

The latest developments about test ids uniformization, as well as #146 and pytest-dev/pytest#8155, made me realize that maybe the fixture union engine could be extended to natively support hybrid param+fixture unions.

If this works this would have two benefits:

However... it will probably be hard to do. A few things to do:

Not an easy ride but might be worth the shot in 2021

@smarie smarie added the enhancement New feature or request label Dec 16, 2020
@smarie
Copy link
Owner Author

smarie commented Dec 17, 2020

After sleeping on this I think the right order would better be:

    1. @parametrize does not need to create a test wrapper anymore. It needs to stop creating ParamAlternatives and instead just pass the argvalues as is. All argvalues containing fixture_ref, possibly marked, possibly nested in tuples, etc., need to be replaced with an easier to use object for example ValueWithFixtureRefs, remembering if the fixture ref is used for the whole tuple or for parts of it (possibly several).
    1. in FixtureClosureNode._build_closure, we should check that the corresponding parameter still pops in the received list. There is a need to detect that this parameter is special (because it contains fixture_refs). For this, the argvalues are currently inspected with
      from inspect import signature, Parameter
      . This should therefore be modified so that it returns true if at least one ValueWithFixtureRefs is detected in the list.
    1. In the pytest_runtest_setup hook, this special ValueWithFixtureRefs object will probably need to be resolved using request._getfixture (?). For this a convenience ValueWithFixtureRefs.resolve(self, request_or_item) method on the object seems appropriate.
      def pytest_runtest_setup(item):

@smarie
Copy link
Owner Author

smarie commented Dec 18, 2020

Another way to say the above is "before I thought that fixture unions were the core and parametrize would reuse this, but we have to revert this pattern: a fixture union is "just" a parametrized fixture with only fixture_ref argvalues. So @parametrize should be the core mechanism.

Another thing we'll need to do in this refactoring, as discussed in #158, is to support parametrized lazy_value and lazy_value requiring fixtures. This would enable us to remove all the fixture-creating "tricks" in @parametrize_with_cases.

This plan becomes clearer and clearer, I'm optimistic for 2021 ! But as always, devil will be in the tiny details: custom ids, custom marks, custom fixture scopes, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant