Skip to content

Commit

Permalink
Run all tests at once to get better coverage overview (#2303)
Browse files Browse the repository at this point in the history
* Run all tests at once to get better coverage overview

* test resources: skip if running on env without docker

* lower coverage minimum to 45
  • Loading branch information
myakove authored Jan 30, 2025
1 parent dfa9792 commit 62852f4
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 69 deletions.
66 changes: 36 additions & 30 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
[tool.pytest.ini_options]
markers = [
"incremental: Mark tests as incremental",
"kubevirt: Mark tests as kubevirt tests"
"kubevirt: Mark tests as kubevirt tests",
]
addopts = [
"--pdbcls=IPython.terminal.debugger:TerminalPdb",
"--cov-config=pyproject.toml",
"--cov-report=html",
"--cov-report=term",
"--cov=ocp_resources"
"--cov=ocp_resources.resource",
"--cov=ocp_resources.utils.resource_constants",
"--cov=ocp_resources.utils.constants",
"--cov=ocp_resources.utils.utils",
"--cov=ocp_resources.exceptions",
"--cov=class_generator",
]

[tool.coverage.run]
omit = [ "tests/*" ]
omit = ["tests/*", "class_generator/tests/*", "class_generator/scripts/tests/*"]

[tool.coverage.report]
fail_under = 45
skip_empty = true

[tool.coverage.html]
Expand All @@ -26,19 +32,19 @@ line-length = 120
fix = true
output-format = "grouped"

[tool.ruff.format]
exclude = [ ".git", ".venv", ".mypy_cache", ".tox", "__pycache__" ]
[tool.ruff.format]
exclude = [".git", ".venv", ".mypy_cache", ".tox", "__pycache__"]

[tool.mypy]
no_implicit_optional = true
show_error_codes = true
warn_unused_ignores = true

[tool.hatch.build.targets.wheel]
packages = [ "ocp_resources", "class_generator" ]
packages = ["ocp_resources", "class_generator"]

[tool.uv]
dev-dependencies = [ "ipdb>=0.13.13", "ipython>=8.12.3" ]
dev-dependencies = ["ipdb>=0.13.13", "ipython>=8.12.3"]

[project]
requires-python = ">=3.9"
Expand All @@ -47,10 +53,10 @@ version = "11.0.24"
description = "Wrapper around https://github.com/kubernetes-client/python"
readme = "README.md"
license = "Apache-2.0"
keywords = [ "Openshift", "Kubevirt", "Openshift Virtualization" ]
keywords = ["Openshift", "Kubevirt", "Openshift Virtualization"]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent"
"Operating System :: OS Independent",
]
dependencies = [
"click>=8.1.7",
Expand All @@ -70,34 +76,34 @@ dependencies = [
"ruff>=0.6.9",
"testcontainers>=4.9.0",
"timeout-sampler>=0.0.46",
"xmltodict>=0.13.0"
"xmltodict>=0.13.0",
]

[[project.authors]]
name = "Meni Yakove"
email = "[email protected]"
[[project.authors]]
name = "Meni Yakove"
email = "[email protected]"

[[project.authors]]
name = "Ruth Netser"
email = "[email protected]"
[[project.authors]]
name = "Ruth Netser"
email = "[email protected]"

[[project.maintainers]]
name = "Meni Yakove"
email = "[email protected]"
[[project.maintainers]]
name = "Meni Yakove"
email = "[email protected]"

[[project.maintainers]]
name = "Ruth Netser"
email = "[email protected]"
[[project.maintainers]]
name = "Ruth Netser"
email = "[email protected]"

[project.urls]
homepage = "https://github.com/RedHatQE/openshift-python-wrapper"
documentation = "https://openshift-python-wrapper.readthedocs.io/en/latest/"
Download = "https://pypi.org/project/openshift-python-wrapper/"
"Bug Tracker" = "https://github.com/RedHatQE/openshift-python-wrapper/issues"
[project.urls]
homepage = "https://github.com/RedHatQE/openshift-python-wrapper"
documentation = "https://openshift-python-wrapper.readthedocs.io/en/latest/"
Download = "https://pypi.org/project/openshift-python-wrapper/"
"Bug Tracker" = "https://github.com/RedHatQE/openshift-python-wrapper/issues"

[project.scripts]
class-generator = "class_generator.class_generator:main"
[project.scripts]
class-generator = "class_generator.class_generator:main"

[build-system]
requires = [ "hatchling" ]
requires = ["hatchling"]
build-backend = "hatchling.build"
12 changes: 8 additions & 4 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import yaml
from docker.errors import DockerException
import kubernetes
from testcontainers.k3s import K3SContainer

Expand All @@ -10,7 +11,7 @@
from ocp_resources.secret import Secret


class TestSecretExit(Secret):
class SecretTestExit(Secret):
def deploy(self, wait: bool = False):
return self

Expand All @@ -20,8 +21,11 @@ def clean_up(self, wait: bool = True, timeout: int | None = None) -> bool:

@pytest.fixture(scope="session")
def client():
with K3SContainer() as k3s:
yield get_client(config_dict=yaml.safe_load(k3s.config_yaml()))
try:
with K3SContainer() as k3s:
yield get_client(config_dict=yaml.safe_load(k3s.config_yaml()))
except DockerException:
pytest.skip("K3S container not available")


@pytest.fixture(scope="class")
Expand Down Expand Up @@ -102,7 +106,7 @@ def test_resource_context_manager(self, client):

def test_resource_context_manager_exit(self, client):
with pytest.raises(ResourceTeardownError):
with TestSecretExit(name="test-context-manager-exit", namespace="default", client=client):
with SecretTestExit(name="test-context-manager-exit", namespace="default", client=client):
pass

def test_proxy_enabled_but_no_proxy_set(self, monkeypatch):
Expand Down
37 changes: 2 additions & 35 deletions tox.toml
Original file line number Diff line number Diff line change
@@ -1,40 +1,7 @@
skipsdist = true
env_list = [
"validate-resources",
"validate-resources-script",
"class-generator",
"resource-tests",
"api-group-order",
"validate-unittests",
]

[env.resource-tests]
description = "Run resource tests on local cluster (k3d)"
passenv = ["KUBECONFIG"]
deps = ["uv"]
commands = [["uv", "run", "pytest", "tests/test_resources.py"]]

[env.validate-resources]
description = "Run validation resources tests"
deps = ["uv"]
commands = [["uv", "run", "pytest", "tests/test_validate_resources.py"]]

[env.validate-resources-script]
description = "Run validation resources script tests (test the script itself, not the resources)"
deps = ["uv"]
commands = [["uv", "run", "pytest", "tests/test_validate_resources_script.py"]]

[env.class-generator]
description = "Run class generator tests"
deps = ["uv"]
commands = [["uv", "run", "pytest", "class_generator/"]]

[env.api-group-order]
description = "Run API group order tests"
deps = ["uv"]
commands = [["uv", "run", "pytest", "tests/test_api_group_order.py"]]
env_list = ["unittests"]

[env.unittests]
description = "Run unittests"
deps = ["uv"]
commands = [["uv", "run", "pytest", "tests/test_unittests.py", "-svv"]]
commands = [["uv", "run", "pytest"]]

0 comments on commit 62852f4

Please sign in to comment.