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

Add Ruff pytest standards #12796

Merged
merged 1 commit into from
Nov 2, 2023
Merged

Conversation

JacobCallahan
Copy link
Member

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.

@JacobCallahan JacobCallahan added CherryPick PR needs CherryPick to previous branches 6.12.z Introduced in or relating directly to Satellite 6.12 6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 labels Oct 3, 2023
@JacobCallahan JacobCallahan requested review from a team as code owners October 3, 2023 16:07
@JacobCallahan JacobCallahan marked this pull request as draft October 3, 2023 16:07
@JacobCallahan
Copy link
Member Author

JacobCallahan commented Oct 3, 2023

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 request.addfinalizer.

@sambible
Copy link
Contributor

sambible commented Oct 3, 2023

335 changes
Need to make a story on our board to review this bad boy

@JacobCallahan
Copy link
Member Author

@sambible please do!

Copy link
Member

@jyejare jyejare left a 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_fixtures/component/satellite_auth.py Outdated Show resolved Hide resolved
tests/foreman/api/test_acs.py Outdated Show resolved Hide resolved
tests/foreman/api/test_capsulecontent.py Outdated Show resolved Hide resolved
tests/foreman/api/test_http_proxy.py Outdated Show resolved Hide resolved
tests/foreman/api/test_rhcloud_inventory.py Outdated Show resolved Hide resolved
pytest_fixtures/component/satellite_auth.py Outdated Show resolved Hide resolved
@pytest.mark.tier1
@pytest.mark.parametrize('public', (True, False))
@pytest.mark.tier1()
@pytest.mark.parametrize('public', [True, False])
Copy link
Contributor

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

Copy link
Member Author

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']
Copy link
Contributor

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

Copy link
Member Author

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'),
Copy link
Contributor

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

Copy link
Member Author

@JacobCallahan JacobCallahan Oct 5, 2023

Choose a reason for hiding this comment

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

tests/foreman/api/test_repositories.py Outdated Show resolved Hide resolved
@@ -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):
Copy link
Contributor

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

Copy link
Member Author

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?

Copy link
Contributor

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

Copy link
Contributor

@Griffin-Sullivan Griffin-Sullivan left a 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!

Copy link
Member

@ogajduse ogajduse left a 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.

pytest_fixtures/component/satellite_auth.py Outdated Show resolved Hide resolved
tests/foreman/api/test_capsulecontent.py Outdated Show resolved Hide resolved
tests/foreman/api/test_rhcloud_inventory.py Outdated Show resolved Hide resolved
tests/foreman/api/test_http_proxy.py Outdated Show resolved Hide resolved
tests/foreman/ui/test_discoveryrule.py Show resolved Hide resolved
Comment on lines -269 to +241
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
Copy link
Member

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.

Copy link
Contributor

@adarshdubey-star adarshdubey-star left a 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.

Copy link
Contributor

@shubhamsg199 shubhamsg199 left a 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.

Comment on lines +133 to +136
@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
Copy link
Collaborator

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 ?

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 was a manual change based on one of the new rules ruff enforces.

@JacobCallahan JacobCallahan force-pushed the ruff_pyt branch 2 times, most recently from 15877b3 to b149a0b Compare October 20, 2023 17:26
@JacobCallahan
Copy link
Member Author

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.

@JacobCallahan JacobCallahan force-pushed the ruff_pyt branch 2 times, most recently from 9aec969 to 0a67c98 Compare October 20, 2023 17:39
@JacobCallahan JacobCallahan marked this pull request as ready for review October 20, 2023 17:55
Copy link
Member

@jyejare jyejare left a 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 !

tests/foreman/api/test_http_proxy.py Show resolved Hide resolved
tests/foreman/ui/test_contenthost.py Outdated Show resolved Hide resolved
@jyejare
Copy link
Member

jyejare commented Nov 2, 2023

@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.
@jyejare jyejare enabled auto-merge (squash) November 2, 2023 13:59
@jyejare jyejare merged commit 83ca284 into SatelliteQE:master Nov 2, 2023
5 checks passed
@JacobCallahan JacobCallahan deleted the ruff_pyt branch November 2, 2023 14:20
@Gauravtalreja1 Gauravtalreja1 mentioned this pull request Dec 6, 2023
shweta83 pushed a commit to shweta83/robottelo that referenced this pull request Apr 10, 2024
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.12.z Introduced in or relating directly to Satellite 6.12 6.13.z Introduced in or relating directly to Satellite 6.13 6.14.z Introduced in or relating directly to Satellite 6.14 CherryPick PR needs CherryPick to previous branches
Projects
None yet
Development

Successfully merging this pull request may close these issues.