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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ select = [
"F", # flake8
"I", # isort
# "Q", # flake8-quotes
"PT", # flake8-pytest
"UP", # pyupgrade
"W", # pycodestyle
]

ignore = [
"E501", # line too long - handled by black
"PT004", # pytest underscrore prefix for non-return fixtures
"PT005", # pytest no underscrore prefix for return fixtures
]

[tool.ruff.isort]
Expand All @@ -40,6 +43,9 @@ known-first-party = [
]
combine-as-imports = true

[tool.ruff.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false

[tool.ruff.flake8-quotes]
inline-quotes = "single"
Expand Down
2 changes: 1 addition & 1 deletion pytest_fixtures/component/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from robottelo.config import settings


@pytest.fixture(scope='function')
@pytest.fixture
def setup_http_proxy(request, module_manifest_org, target_sat):
"""Create a new HTTP proxy and set related settings based on proxy"""
http_proxy = target_sat.api_factory.make_http_proxy(module_manifest_org, request.param)
Expand Down
2 changes: 1 addition & 1 deletion pytest_fixtures/component/katello_certs_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def certs_data(sat_ready_rhel):
cert_data['key_file_name'] = f'{sat_ready_rhel.hostname}/{sat_ready_rhel.hostname}.key'
cert_data['cert_file_name'] = f'{sat_ready_rhel.hostname}/{sat_ready_rhel.hostname}.crt'
sat_ready_rhel.custom_cert_generate(cert_data['capsule_hostname'])
yield cert_data
return cert_data


@pytest.fixture
Expand Down
4 changes: 2 additions & 2 deletions pytest_fixtures/component/lce.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def module_lce(module_org, module_target_sat):
return module_target_sat.api.LifecycleEnvironment(organization=module_org).create()


@pytest.fixture(scope='function')
@pytest.fixture
def function_lce(function_org, target_sat):
return target_sat.api.LifecycleEnvironment(organization=function_org).create()

Expand All @@ -31,7 +31,7 @@ def module_lce_library(module_org, module_target_sat):
)


@pytest.fixture(scope='function')
@pytest.fixture
def function_lce_library(function_org, target_sat):
"""Returns the Library lifecycle environment from chosen organization"""
return (
Expand Down
4 changes: 2 additions & 2 deletions pytest_fixtures/component/maintain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def module_stash(request):
# Please refer the documentation for more details on stash
# https://docs.pytest.org/en/latest/reference/reference.html#stash
request.node.stash[synced_repos] = {}
yield request.node.stash
return request.node.stash


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -98,7 +98,7 @@ def module_synced_repos(sat_maintain, module_capsule_configured, module_sca_mani
sync_status = module_capsule_configured.nailgun_capsule.content_sync()
assert sync_status['result'] == 'success'

yield {
return {
'custom': module_stash[synced_repos]['cust_repo'],
'rh': module_stash[synced_repos]['rh_repo'],
}
Expand Down
8 changes: 4 additions & 4 deletions pytest_fixtures/component/provision_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@
@pytest.fixture(scope='session')
def sat_azure(request, session_puppet_enabled_sat, session_target_sat):
hosts = {'sat': session_target_sat, 'puppet_sat': session_puppet_enabled_sat}
yield hosts[request.param]
return hosts[request.param]


@pytest.fixture(scope='module')
def sat_azure_org(sat_azure):
yield sat_azure.api.Organization().create()
return sat_azure.api.Organization().create()


@pytest.fixture(scope='module')
def sat_azure_loc(sat_azure):
yield sat_azure.api.Location().create()
return sat_azure.api.Location().create()


@pytest.fixture(scope='module')
def sat_azure_domain(sat_azure, sat_azure_loc, sat_azure_org):
yield sat_azure.api.Domain(location=[sat_azure_loc], organization=[sat_azure_org]).create()
return sat_azure.api.Domain(location=[sat_azure_loc], organization=[sat_azure_org]).create()


@pytest.fixture(scope='module')
Expand Down
10 changes: 5 additions & 5 deletions pytest_fixtures/component/provision_gce.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@
@pytest.fixture(scope='session')
def sat_gce(request, session_puppet_enabled_sat, session_target_sat):
hosts = {'sat': session_target_sat, 'puppet_sat': session_puppet_enabled_sat}
yield hosts[getattr(request, 'param', 'sat')]
return hosts[getattr(request, 'param', 'sat')]


@pytest.fixture(scope='module')
def sat_gce_org(sat_gce):
yield sat_gce.api.Organization().create()
return sat_gce.api.Organization().create()


@pytest.fixture(scope='module')
def sat_gce_loc(sat_gce):
yield sat_gce.api.Location().create()
return sat_gce.api.Location().create()


@pytest.fixture(scope='module')
def sat_gce_domain(sat_gce, sat_gce_loc, sat_gce_org):
yield sat_gce.api.Domain(location=[sat_gce_loc], organization=[sat_gce_org]).create()
return sat_gce.api.Domain(location=[sat_gce_loc], organization=[sat_gce_org]).create()


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -282,7 +282,7 @@ def module_gce_finishimg(
return finish_image


@pytest.fixture()
@pytest.fixture
def gce_setting_update(sat_gce):
sat_gce.update_setting('destroy_vm_on_host_delete', True)
yield
Expand Down
2 changes: 1 addition & 1 deletion pytest_fixtures/component/provision_libvirt.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ def module_libvirt_image(module_target_sat, module_cr_libvirt):
def module_libvirt_provisioning_sat(module_provisioning_sat):
# Configure Libvirt CR for provisioning
module_provisioning_sat.sat.configure_libvirt_cr()
yield module_provisioning_sat
return module_provisioning_sat
8 changes: 4 additions & 4 deletions pytest_fixtures/component/puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,22 @@ def session_puppet_enabled_sat(session_satellite_host):
def session_puppet_enabled_capsule(session_capsule_host, session_puppet_enabled_sat):
"""Capsule with enabled puppet plugin"""
session_capsule_host.capsule_setup(sat_host=session_puppet_enabled_sat)
yield session_capsule_host.enable_puppet_capsule(satellite=session_puppet_enabled_sat)
return session_capsule_host.enable_puppet_capsule(satellite=session_puppet_enabled_sat)


@pytest.fixture(scope='module')
def module_puppet_org(session_puppet_enabled_sat):
yield session_puppet_enabled_sat.api.Organization().create()
return session_puppet_enabled_sat.api.Organization().create()


@pytest.fixture(scope='module')
def module_puppet_loc(session_puppet_enabled_sat):
yield session_puppet_enabled_sat.api.Location().create()
return session_puppet_enabled_sat.api.Location().create()


@pytest.fixture(scope='module')
def module_puppet_domain(session_puppet_enabled_sat, module_puppet_loc, module_puppet_org):
yield session_puppet_enabled_sat.api.Domain(
return session_puppet_enabled_sat.api.Domain(
location=[module_puppet_loc], organization=[module_puppet_org]
).create()

Expand Down
6 changes: 3 additions & 3 deletions pytest_fixtures/component/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def module_repo(module_repo_options, module_target_sat):
return module_target_sat.api.Repository(**module_repo_options).create()


@pytest.fixture(scope='function')
@pytest.fixture
def function_product(function_org):
return entities.Product(organization=function_org).create()

Expand Down Expand Up @@ -74,7 +74,7 @@ def module_rhst_repo(module_target_sat, module_org_with_manifest, module_promote
return REPOS['rhst7']['id']


@pytest.fixture(scope="function")
@pytest.fixture
def repo_setup():
"""
This fixture is used to create an organization, product, repository, and lifecycle environment
Expand All @@ -86,7 +86,7 @@ def repo_setup():
repo = entities.Repository(name=repo_name, product=product).create()
lce = entities.LifecycleEnvironment(organization=org).create()
details = {'org': org, 'product': product, 'repo': repo, 'lce': lce}
yield details
return details


@pytest.fixture(scope='module')
Expand Down
6 changes: 3 additions & 3 deletions pytest_fixtures/component/rh_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def rhcloud_activation_key(module_target_sat, rhcloud_manifest_org):
purpose_role='test-role',
auto_attach=False,
).create()
yield ak
return ak


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -62,7 +62,7 @@ def rhel_insights_vm(
module_target_sat.generate_inventory_report(rhcloud_manifest_org)
# Sync inventory status
module_target_sat.sync_inventory_status(rhcloud_manifest_org)
yield rhel_contenthost
return rhel_contenthost


@pytest.fixture
Expand Down Expand Up @@ -90,4 +90,4 @@ def rhcloud_capsule(module_capsule_host, module_target_sat, rhcloud_manifest_org
'location-ids': default_location.id,
}
)
yield module_capsule_host
return module_capsule_host
14 changes: 7 additions & 7 deletions pytest_fixtures/component/satellite_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def default_ipa_host(module_target_sat):
return IPAHost(module_target_sat)


@pytest.fixture()
@pytest.fixture
def ldap_cleanup():
"""this is an extra step taken to clean any existing ldap source"""
ldap_auth_sources = entities.AuthSourceLDAP().search()
Expand All @@ -44,7 +44,7 @@ def ldap_cleanup():
for user in users:
user.delete()
ldap_auth.delete()
yield
return


@pytest.fixture(scope='session')
Expand Down Expand Up @@ -104,7 +104,7 @@ def open_ldap_data():
}


@pytest.fixture(scope='function')
@pytest.fixture
def auth_source(ldap_cleanup, module_org, module_location, ad_data):
ad_data = ad_data()
return entities.AuthSourceLDAP(
Expand All @@ -127,7 +127,7 @@ def auth_source(ldap_cleanup, module_org, module_location, ad_data):
).create()


@pytest.fixture(scope='function')
@pytest.fixture
def auth_source_ipa(ldap_cleanup, default_ipa_host, module_org, module_location):
return entities.AuthSourceLDAP(
onthefly_register=True,
Expand All @@ -149,7 +149,7 @@ def auth_source_ipa(ldap_cleanup, default_ipa_host, module_org, module_location)
).create()


@pytest.fixture(scope='function')
@pytest.fixture
def auth_source_open_ldap(ldap_cleanup, module_org, module_location, open_ldap_data):
return entities.AuthSourceLDAP(
onthefly_register=True,
Expand Down Expand Up @@ -259,7 +259,7 @@ def ldap_auth_source(
else:
ldap_data['server_type'] = LDAP_SERVER_TYPE['UI']['posix']
ldap_data['attr_login'] = LDAP_ATTR['login']
yield ldap_data, auth_source
return ldap_data, auth_source


@pytest.fixture
Expand Down Expand Up @@ -459,7 +459,7 @@ def configure_hammer_no_negotiate(parametrized_enrolled_sat):


@pytest.mark.external_auth
@pytest.fixture(scope='function')
@pytest.fixture
def hammer_logout(parametrized_enrolled_sat):
"""Logout in Hammer."""
result = parametrized_enrolled_sat.cli.Auth.logout()
Expand Down
2 changes: 1 addition & 1 deletion pytest_fixtures/component/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest


@pytest.fixture()
@pytest.fixture
def setting_update(request, target_sat):
"""
This fixture is used to create an object of the provided settings parameter that we use in
Expand Down
8 changes: 4 additions & 4 deletions pytest_fixtures/component/taxonomy.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,15 +212,15 @@ def class_sca_manifest():
yield manifest


@pytest.fixture(scope='function')
@pytest.fixture
def function_entitlement_manifest():
"""Yields a manifest in entitlement mode with subscriptions determined by the
`manifest_category.entitlement` setting in conf/manifest.yaml."""
with Manifester(manifest_category=settings.manifest.entitlement) as manifest:
yield manifest


@pytest.fixture(scope='function')
@pytest.fixture
def function_secondary_entitlement_manifest():
"""Yields a manifest in entitlement mode with subscriptions determined by the
`manifest_category.entitlement` setting in conf/manifest.yaml.
Expand All @@ -229,7 +229,7 @@ def function_secondary_entitlement_manifest():
yield manifest


@pytest.fixture(scope='function')
@pytest.fixture
def function_sca_manifest():
"""Yields a manifest in Simple Content Access mode with subscriptions determined by the
`manifest_category.golden_ticket` setting in conf/manifest.yaml."""
Expand All @@ -245,7 +245,7 @@ def smart_proxy_location(module_org, module_target_sat, default_smart_proxy):
return location


@pytest.fixture(scope='function')
@pytest.fixture
def upgrade_entitlement_manifest():
"""Returns a manifest in entitlement mode with subscriptions determined by the
`manifest_category.entitlement` setting in conf/manifest.yaml. used only for
Expand Down
6 changes: 3 additions & 3 deletions pytest_fixtures/component/templatesync.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from robottelo.logging import logger


@pytest.fixture()
@pytest.fixture
def create_import_export_local_dir(target_sat):
"""Creates a local directory inside root_dir on satellite from where the templates will
be imported from or exported to.
Expand Down Expand Up @@ -76,7 +76,7 @@ def git_pub_key(session_target_sat, git_port):
res.raise_for_status()


@pytest.fixture(scope='function')
@pytest.fixture
def git_repository(git_port, git_pub_key, request):
"""Creates a new repository on git provider for exporting templates.
Expand All @@ -96,7 +96,7 @@ def git_repository(git_port, git_pub_key, request):
res.raise_for_status()


@pytest.fixture()
@pytest.fixture
def git_branch(git_repository):
"""Creates a new branch in the git repository for exporting templates.
Expand Down
Loading
Loading