-
Notifications
You must be signed in to change notification settings - Fork 115
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
Add Ruff pytest standards #12796
Add Ruff pytest standards #12796
Conversation
There are a few ruff checks that will fail in this initial version until I can contact component owners to decide how we want to handle the recommendations. The most complex of which are using |
|
@sambible please do! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Round 1 Review !
@pytest.mark.tier1 | ||
@pytest.mark.parametrize('public', (True, False)) | ||
@pytest.mark.tier1() | ||
@pytest.mark.parametrize('public', [True, False]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting, any particular reason for the change here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -137,15 +137,15 @@ def test_negative_update_parameter_type(self, test_data, module_puppet): | |||
2. Error raised for invalid default value. | |||
""" | |||
sc_param = module_puppet['sc_params'].pop() | |||
sc_param.override = True | |||
sc_param.parameter_type = test_data['sc_type'] | |||
sc_param.default_value = test_data['value'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's taking out the stuff from the raises block that's not a function call. idk how I feel about this stylistically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the point of this change is to make sure that only the call that raises the error should be in the context manager. there are no functional reasons why these extra lines should be under that context.
@pytest.mark.parametrize( | ||
'name, new_name', | ||
('name', 'new_name'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does putting this in a tuple have any affect on the functionality here? I don't think so, but just curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -1238,6 +1238,7 @@ def test_positive_taxonomies_control_to_superadmin_without_org_admin( | |||
entities.User(id=user.id).delete() | |||
with pytest.raises(HTTPError): | |||
user_role.read() | |||
with pytest.raises(HTTPError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks worse to me than just having 2 calls in the same raises block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which is more functionally correct for the test, though?
shouldn't both raise HTTPErrors?
what if the user_role.read()
doesn't raise an HTTPError but user.read()
does?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are definitely right, this is more correct. I'm assuming the second statement here hasn't ever executed, actually, since the first statement will always raise an error ( it's been deleted ) and you'd leave the ocntext
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to Platform owned tests / fixtures look good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is huge! ACK with minor and non-blocking comments.
try: | ||
with pytest.raises(Exception) as exc_info: # noqa: PT011 - TODO determine better exception | ||
get_configure_option("ahv_internal_debug", config_file) | ||
except Exception as VirtWhoError: | ||
assert env_error == str(VirtWhoError) | ||
assert str(exc_info.value) == env_error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yanpliu Can you please have a look at this one? We do not have to address it in this PR necessarily, but it would be good to keep the existence of this TODO in mind.
https://docs.astral.sh/ruff/rules/pytest-raises-too-broad/
Note: this construct is present across the test modules that are owned by the virt-who team.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to the rocket team components look valid to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes to Rocket team tests and fixtures look good to me.
@pytest.mark.usefixtures('_clean_scenario') | ||
@pytest.mark.parametrize('count', list(range(1, 10))) | ||
def test_post_puppet_class_parameter_data_and_type( | ||
self, count, _clean_scenario, class_pre_upgrade_data, class_target_sat | ||
self, count, class_pre_upgrade_data, class_target_sat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wondering, if this change to use usefixtures here made by ruff ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was a manual change based on one of the new rules ruff enforces.
15877b3
to
b149a0b
Compare
Major update to the PR. After additional feedback, I've dropped the requirements for parentheses after fixtures and marks. I've also incorporated the logic changes previously discussed above. |
9aec969
to
0a67c98
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK pending minor comments !
0a67c98
to
19ee4f5
Compare
@JacobCallahan I was planning to merge it now ! And unfortunately I see conflicts holding it up ! Please resolve them :( |
This is a big one! Most of the changes are automatic, but a number of these are manual. I've deselected rules relating to fixture naming, but we can have a conversation later about whether we want to adopt the underscore naming conventions for fixtures.
19ee4f5
to
fee22e8
Compare
This is a big one! Most of the changes are automatic, but a number of these are manual. I've deselected rules relating to fixture naming, but we can have a conversation later about whether we want to adopt the underscore naming conventions for fixtures.
This is a big one! Most of the changes are automatic, but a number of these are manual. I've deselected rules relating to fixture naming, but we can have a conversation later about whether we want to adopt the underscore naming conventions for fixtures.