Skip to content

Commit

Permalink
[WIP]: Enable flake8-pytest-style plugin for ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
cutwater committed Oct 21, 2024
1 parent e908016 commit 1bfae3d
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 50 deletions.
8 changes: 4 additions & 4 deletions galaxy_ng/tests/integration/api/test_aiindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@
from ..utils.legacy import cleanup_social_user


@pytest.fixture(scope="function")
@pytest.fixture
def flags(ansible_config):
config = ansible_config("admin")
api_client = get_client(config, request_token=True, require_auth=True)
api_prefix = api_client.config.get("api_prefix").rstrip("/")
return api_client(f"{api_prefix}/_ui/v1/feature-flags/")


@pytest.fixture(scope="function")
@pytest.fixture
def namespace(ansible_config, galaxy_client) -> str:
"""create a new namespace."""
gc = galaxy_client("partner_engineer")
return create_test_namespace(gc)


@pytest.fixture(scope="function")
@pytest.fixture
def pe_namespace(ansible_config, galaxy_client) -> str:
"""create a new namespace owned by PE user."""
config = ansible_config("partner_engineer")
Expand All @@ -53,7 +53,7 @@ def pe_namespace(ansible_config, galaxy_client) -> str:
return new_namespace


@pytest.fixture(scope="function")
@pytest.fixture
def legacy_namespace(ansible_config):
"""Creates a new legacy namespace owned by gh01 user"""

Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
pytestmark = pytest.mark.qa # noqa: F821


@pytest.mark.parametrize("profile", ("basic_user", "partner_engineer", "org_admin", "admin"))
@pytest.mark.parametrize("profile", ["basic_user", "partner_engineer", "org_admin", "admin"])
@pytest.mark.deployment_standalone
@pytest.mark.galaxyapi_smoke
@pytest.mark.skip_in_gw
Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/api/test_collection_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@
NAMESPACE = "signing"


@pytest.fixture(scope="function")
@pytest.fixture
def flags(galaxy_client):
gc = galaxy_client("admin")
return gc.get("_ui/v1/feature-flags/")


@pytest.fixture(scope="function", autouse=True)
@pytest.fixture(autouse=True)
def namespace(galaxy_client):
# ensure namespace exists
gc = galaxy_client("admin")
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_container_signing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from galaxykit.utils import wait_for_task


@pytest.fixture(scope="function")
@pytest.fixture
def flags(galaxy_client):
gc = galaxy_client("admin")
return gc.get("_ui/v1/feature-flags/")
Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def test_gw_group_role_listing(galaxy_client, settings, test_data):
assert f'/groups/{group_response["id"]}/' in group_roles_response["results"][0]["pulp_href"]

delete_group_v3(gc, group_name)
with pytest.raises(ValueError):
get_group_v3(gc, group_name)
# with pytest.raises(ValueError):
get_group_v3(gc, group_name)


@pytest.mark.parametrize(
Expand Down
20 changes: 8 additions & 12 deletions galaxy_ng/tests/integration/api/test_iqe_rbac.py
Original file line number Diff line number Diff line change
Expand Up @@ -759,13 +759,11 @@ def test_missing_object_role_push_image_to_ee(self, galaxy_client, ansible_confi
ee_name = create_emtpy_local_image_container(ansible_config("admin"), gc)
user, _ = add_new_user_to_new_group(gc)
gc_user = galaxy_client(user)
try:
# We expect the underlying podman command to fail, but we don't
# want to accidentally catch any other error, so we check that
# the error is the podman return code.
with pytest.raises(GalaxyClientError, match="retcode"):
gc_user.push_image(ee_name + ":latest")
except GalaxyClientError as e:
# We expect the underlying podman command to fail, but we don't
# want to accidentally catch any other error, so we check that
# the error is the podman return code.
assert "retcode" in str(e)

@pytest.mark.iqe_rbac_test
def test_object_role_push_image_to_ee(self, galaxy_client, ansible_config):
Expand Down Expand Up @@ -816,13 +814,11 @@ def test_missing_global_role_push_image_to_ee(self, galaxy_client, ansible_confi
gc.add_role_to_group(role_user, group["id"])
ee_name = create_emtpy_local_image_container(ansible_config("admin"), gc)
gc_user = galaxy_client(user)
try:
# We expect the underlying podman command to fail, but we don't
# want to accidentally catch any other error, so we check that
# the error is the podman return code.
with pytest.raises(GalaxyClientError, match="retcode"):
gc_user.push_image(ee_name + ":latest")
except GalaxyClientError as e:
# We expect the underlying podman command to fail, but we don't
# want to accidentally catch any other error, so we check that
# the error is the podman return code.
assert "retcode" in str(e)

@pytest.mark.iqe_rbac_test
def test_missing_object_role_delete_image_from_ee(self, galaxy_client, ansible_config):
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_ldap.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
log = logging.getLogger(__name__)


@pytest.fixture(scope="function")
@pytest.fixture
def settings(ansible_config):
config = ansible_config("admin")
api_prefix = config.get("api_prefix").rstrip("/")
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/api/test_x_repo_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ def test_search_by_version(self, galaxy_client):

# FIXME: unskip when https://issues.redhat.com/browse/AAP-32675 is merged
@pytest.mark.skip_in_gw
@pytest.mark.parametrize("is_highest,cv_version", [(True, "4.0.2"), (False, "4.0.1")])
@pytest.mark.parametrize(("is_highest", "cv_version"), [(True, "4.0.2"), (False, "4.0.1")])
@pytest.mark.x_repo_search
def test_search_is_highest_true_false(self, galaxy_client, is_highest, cv_version):
"""
Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/cli/test_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DependencySpec:
@pytest.mark.skip_in_gw
@pytest.mark.parametrize(
"params",
(
[
DependencySpec("normal", "1.0.0", 0),
DependencySpec("exact", "=1.0.0", 0),
DependencySpec("lt", "<2.0.0", 0),
Expand All @@ -40,7 +40,7 @@ class DependencySpec:
# DependencySpec("exception", ">0.0.0,!=1.0.0", 1, xfail="galaxy-dev#104"),
# DependencySpec("missing1", "2.0.0", 1, xfail="galaxy-dev#104"),
# DependencySpec("missing2", ">1.0.0", 1, xfail="galaxy-dev#104"),
),
],
ids=lambda s: s.name,
)
def test_collection_dependency_install(ansible_config, published, cleanup_collections,
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/integration/community/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def my_setup_module(ansible_config):
},
)
resp = upload_artifact(admin_config, admin_client, artifact)
resp = wait_for_task(admin_client, resp)
wait_for_task(admin_client, resp)
"""
{'name': 'galaxy_fake_collection', 'namespace': 'ansible', 'description':
'A collection to pretend to manage galaxy with infinidash support', 'type': 'collection',
Expand Down
34 changes: 17 additions & 17 deletions galaxy_ng/tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def ansible_config():
return get_ansible_config()


@pytest.fixture(scope="function")
@pytest.fixture
def published(ansible_config, artifact, galaxy_client):
# make sure the expected namespace exists ...
gc = galaxy_client("partner_engineer")
Expand All @@ -125,7 +125,7 @@ def published(ansible_config, artifact, galaxy_client):
return artifact


@pytest.fixture(scope="function")
@pytest.fixture
def certifiedv2(ansible_config, artifact, galaxy_client):
""" Create and publish+certify collection version N and N+1 """

Expand Down Expand Up @@ -164,7 +164,7 @@ def certifiedv2(ansible_config, artifact, galaxy_client):
return (artifact, artifact2)


@pytest.fixture(scope="function")
@pytest.fixture
def uncertifiedv2(ansible_config, artifact, settings, galaxy_client):
""" Create and publish collection version N and N+1 but only certify N"""

Expand Down Expand Up @@ -204,7 +204,7 @@ def uncertifiedv2(ansible_config, artifact, settings, galaxy_client):
return artifact, artifact2


@pytest.fixture(scope="function")
@pytest.fixture
def auto_approved_artifacts(ansible_config, artifact, galaxy_client):
""" Create and publish collection version N and N+1"""

Expand Down Expand Up @@ -249,7 +249,7 @@ def auto_approved_artifacts(ansible_config, artifact, galaxy_client):
return artifact, artifact2


@pytest.fixture(scope="function")
@pytest.fixture
def artifact():
"""Generate a randomized collection for testing."""

Expand Down Expand Up @@ -384,13 +384,13 @@ def sync_instance_crc():
return (manifest, config)


@pytest.fixture(scope="function")
@pytest.fixture
def settings(galaxy_client):
gc = galaxy_client("admin")
return gc.get("_ui/v1/settings/")


@pytest.fixture(scope="function")
@pytest.fixture
def use_collection_signatures(settings):
"""A shortcut to know if a test should attempt to work with signatures."""
service = settings["GALAXY_COLLECTION_SIGNING_SERVICE"]
Expand All @@ -400,15 +400,15 @@ def use_collection_signatures(settings):
return False


@pytest.fixture(scope="function")
@pytest.fixture
def autohubtest2(galaxy_client):
"""A carry over pre-created namespace from the original IQE tests."""
gc = galaxy_client("admin")
create_namespace(gc, "autohubtest2", "")
return {"name": "autohubtest2"}


@pytest.fixture(scope="function")
@pytest.fixture
def random_namespace(galaxy_client, settings):
"""Make a randomized namespace."""

Expand All @@ -423,7 +423,7 @@ def random_namespace(galaxy_client, settings):
return get_namespace(ns_name, gc=gc)


@pytest.fixture(scope="function")
@pytest.fixture
def random_username(galaxy_client):
"""Make a random username."""
return 'user_' + generate_namespace()
Expand Down Expand Up @@ -531,7 +531,7 @@ def hub_version(ansible_config):
return get_hub_version(ansible_config)


@pytest.fixture(scope="function")
@pytest.fixture
def gh_user_1_post(ansible_config):
"""
Returns a galaxy kit client with a GitHub user logged into beta galaxy stage
Expand All @@ -544,7 +544,7 @@ def gh_user_1_post(ansible_config):
remove_from_cache("github_user")


@pytest.fixture(scope="function")
@pytest.fixture
def gh_user_1(ansible_config):
"""
Returns a galaxy kit client with a GitHub user logged into beta galaxy stage
Expand All @@ -553,7 +553,7 @@ def gh_user_1(ansible_config):
return gc("github_user", github_social_auth=True)


@pytest.fixture(scope="function")
@pytest.fixture
def gh_user_2(ansible_config):
"""
Returns a galaxy kit client with a GitHub user logged into beta galaxy stage
Expand All @@ -562,7 +562,7 @@ def gh_user_2(ansible_config):
return gc("github_user_alt", github_social_auth=True)


@pytest.fixture(scope="function")
@pytest.fixture
def gh_user_1_pre(ansible_config):
"""
Removes everything related to the GitHub user and the user itself and
Expand All @@ -573,7 +573,7 @@ def gh_user_1_pre(ansible_config):
return gc("github_user", github_social_auth=True, ignore_cache=True)


@pytest.fixture(scope="function")
@pytest.fixture
def gw_user_1(ansible_config):
"""
Returns a galaxy kit client with a GitHub user logged into beta galaxy stage
Expand All @@ -582,7 +582,7 @@ def gw_user_1(ansible_config):
return gc("github_user", github_social_auth=True)


@pytest.fixture(scope="function")
@pytest.fixture
def generate_test_artifact(ansible_config):
"""
Generates a test artifact and deletes it after the test
Expand All @@ -600,7 +600,7 @@ def generate_test_artifact(ansible_config):
delete_collection(gc_admin, namespace=artifact.namespace, collection=artifact.name)


@pytest.fixture(scope="function")
@pytest.fixture
def keep_generated_test_artifact(ansible_config):
"""
Generates a test artifact
Expand Down
4 changes: 2 additions & 2 deletions galaxy_ng/tests/integration/utils/oci_env.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import subprocess
import os
from pytest import skip
import pytest


def _set_settings(text):
Expand All @@ -23,7 +23,7 @@ def with_oci_env_setting(settings):
def decorator(function):
def wrapper(*args, **kwargs):
if not os.path.isdir('/opt/oci-env/'):
skip(reason="@with_oci_env_setting tests only work when run in oci-env")
pytest.skip(reason="@with_oci_env_setting tests only work when run in oci-env")

current_settings = _get_settings()
new_settings = current_settings + [f"{x}={settings[x]}" for x in settings]
Expand Down
6 changes: 3 additions & 3 deletions galaxy_ng/tests/performance/test_performance.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
from galaxy_ng.tests.performance.constants import URLS
from ..integration.utils import (
UIClient,
get_client
get_client,
)


@pytest.fixture(scope="function")
@pytest.fixture
def api_client(ansible_config):
config = ansible_config("admin")
api_client = get_client(
Expand All @@ -20,7 +20,7 @@ def api_client(ansible_config):


@pytest.mark.deployment_community
@pytest.mark.parametrize("url,info", URLS.items())
@pytest.mark.parametrize(("url", "info"), URLS.items())
def test_api_performance(ansible_config, api_client, url, info):
threshold = 0.25
results = []
Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/tests/unit/app/test_dynaconf_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def validate(*args, **kwargs):


@pytest.mark.parametrize(
"do_stuff, extra_settings, expected_results",
("do_stuff", "extra_settings", "expected_results"),
[
# 0 >=4.10 no external auth ...
(
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ select = [
"INP",
# pyupgrade
"UP",
# flake8-pytest-style
"PT",
]
extend-ignore = [
# B904 requires using `raise ... from ...` to explicitly tell what to do with "parent"
Expand All @@ -121,6 +123,9 @@ extend-ignore = [
# UP032 Use f-string instead of `format` call.
# No need to replace all str.format usage with f-strings in entire codebase.
"UP032",
# PT009 Use a regular `assert` instead of unittest-style
# Ignoring, since we have mixed pytest and legacy unittest styled tests
"PT009",
]

[tool.ruff.lint.per-file-ignores]
Expand Down

0 comments on commit 1bfae3d

Please sign in to comment.