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

tests: use markers to configure disable_subp_usage #473

Merged
merged 1 commit into from
Jul 2, 2020

Conversation

OddBloke
Copy link
Collaborator

@OddBloke OddBloke commented Jul 2, 2020

This is an improvement over indirect parameterisation for a few reasons:

  • The test code is much easier to read, the mark names are much more
    intuitive than the indirect parameterisation invocation, and there's
    less boilerplate to boot
  • The fixture no longer has to overload the single parameter that
    fixtures can take with multiple meanings

@OddBloke
Copy link
Collaborator Author

OddBloke commented Jul 2, 2020

The use of markers here isn't strictly required, but some pending test work I have will use them in a way that will require their use; I tested the practicality of this approach by refactoring this code, and it results in cleaner test code so I proposed it independent of that pending work.

@blackboxsw blackboxsw self-assigned this Jul 2, 2020
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

This is a vast improvement and much cleaner IMO.minor nit and +1.

conftest.py Outdated
def side_effect(args, *other_args, **kwargs):
raise AssertionError("Unexpectedly used subp.subp")

elif allow_subp_for is not None and allow_all_subp is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we keep the ordering of variable checks consistent as it makes me think harder when reviewing this

Suggested change
elif allow_subp_for is not None and allow_all_subp is not None:
elif allow_all_subp is not None and allow_subp_for is not None:

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah, my bad! Fix pushed.

This is an improvement over indirect parameterisation for a few reasons:

* The test code is much easier to read, the mark names are much more
  intuitive than the indirect parameterisation invocation, and there's
  less boilerplate to boot
* The fixture no longer has to overload the single parameter that
  fixtures can take with multiple meanings
Copy link
Collaborator

@blackboxsw blackboxsw left a comment

Choose a reason for hiding this comment

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

LGTM!

@blackboxsw blackboxsw merged commit 2b72791 into canonical:master Jul 2, 2020
Copy link
Member

@TheRealFalcon TheRealFalcon left a comment

Choose a reason for hiding this comment

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

Sorry, late to the party! But I agree, this is a nice change and the code look a lot nice.

@@ -5,6 +5,18 @@
from cloudinit import subp


def _closest_marker_args_or(request, marker_name: str, default):
Copy link
Member

Choose a reason for hiding this comment

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

is this supposed to be _closest_marker_args_or_default ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'd be happy to land such a change if you want, but (unsurprisingly, as I wrote it 😁) I think its intent is clear (and means that callers can generally call it on a single LOC; though that isn't much of an advantage if this spelling isn't clear!).

If we do want to change it, _get_closest_marker_args might be better, following the underlying API (and dict.get which takes a default)?

Copy link
Member

Choose a reason for hiding this comment

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

No need to change it. I think it's fine. I just wanted to make sure it was what you intended and not an accidental misnaming.

Copy link
Member

Choose a reason for hiding this comment

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

Also, I would like to point out the irony of me pointing out a possible typo, while at the same time writing the code look a lot nice. 😄

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.

3 participants