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

Make pytest plugin resiliant to missing bindings #4851

Merged
merged 1 commit into from Jan 9, 2024

Conversation

mdellweg
Copy link
Member

@mdellweg mdellweg commented Dec 8, 2023

This should eventually make the pytest plugins more lightweight until actually used, and prevent import errors, when bindings that are not supposed to be used are not installed.

_api_client_set.remove(pulpcore_client)


# TODO Deprecate all the api_client fixtures below.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope, we can get a lot of boilerplate out of the way here.

@mdellweg mdellweg force-pushed the lazy_fixtures branch 2 times, most recently from 26f39ee to cb993ee Compare December 8, 2023 20:55
mdellweg added a commit to mdellweg/pulpcore that referenced this pull request Dec 11, 2023
This also provides new pulpcore_bindings and file_bindings fixtures that
will provide all the bindings apis preconfigured.

fixes pulp#4851
@mdellweg mdellweg changed the title WIP Make pytest plugin resiliant to missing bindings Dec 11, 2023
mdellweg added a commit to mdellweg/pulpcore that referenced this pull request Dec 11, 2023
This also provides new pulpcore_bindings and file_bindings fixtures that
will provide all the bindings apis preconfigured.

fixes pulp#4851
mdellweg added a commit to mdellweg/pulpcore that referenced this pull request Dec 11, 2023
This also provides new pulpcore_bindings and file_bindings fixtures that
will provide all the bindings apis preconfigured.

fixes pulp#4851
@mdellweg mdellweg force-pushed the lazy_fixtures branch 2 times, most recently from d0a5ef5 to 80c8d8d Compare December 11, 2023 15:50
"""
A namespace providing preconfigured pulpcore api clients.

e.g. `pulpcore_bindings.WorkersApi.list()`.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also bring us away from the questionable practice of giving these apis new names. (I mean the generated names are not always great, but they are there to be anyway.)


gpg = gnupg.GPG(gnupghome=signing_gpg_homedir_path)

gpg.import_keys(private_key_data)
gpg.import_keys(response.content)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@mdellweg mdellweg force-pushed the lazy_fixtures branch 7 times, most recently from e127d70 to c967512 Compare December 12, 2023 12:47
@mdellweg mdellweg marked this pull request as ready for review December 12, 2023 12:56
@mdellweg mdellweg force-pushed the lazy_fixtures branch 3 times, most recently from c050737 to f6eeadc Compare December 12, 2023 15:48
Copy link
Contributor

@gerrod3 gerrod3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the new approach.

Comment on lines +602 to +605
def _proxy_module():
import proxy

return proxy
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be a session fixture?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh absolutely.

"""
Wait for a task to reach a final state.

Returns the task in "completed" state, or throws a `PulpTaskTimeoutError` in case the timeout
in seconds (defaulting to 30*60) exceeded or a `PulpTaskError` in case it reached any other
final state.
"""
from pulpcore.client.pulpcore import ApiException
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the bindings are in pulpcore_bindings then I don't think we need this import.


def __getattr__(self, name):
# __getattr__ is only consulted if nothing is found in __dict__.
assert name.endswith("Api")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only problem with this assert is that the API classes can have custom names if the view is using drf_spectacular.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example?
I can remove it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gerrod3 I have yet to see one example...

@mdellweg mdellweg force-pushed the lazy_fixtures branch 2 times, most recently from 8820a61 to 67c44e2 Compare December 14, 2023 14:12
This also provides new pulpcore_bindings and file_bindings fixtures that
will provide all the bindings apis preconfigured.

fixes pulp#4751
Copy link
Member

@bmbouter bmbouter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. I like how it simplifies things while adding the lazy loading support.

@mdellweg mdellweg merged commit 9c479e8 into pulp:main Jan 9, 2024
16 checks passed
@mdellweg mdellweg deleted the lazy_fixtures branch January 9, 2024 14:01
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

Successfully merging this pull request may close these issues.

Running unit tests with Pytest is pulling in functional test requirements
5 participants