Skip to content

Commit 62852f4

Browse files
authored
Run all tests at once to get better coverage overview (#2303)
* Run all tests at once to get better coverage overview * test resources: skip if running on env without docker * lower coverage minimum to 45
1 parent dfa9792 commit 62852f4

File tree

3 files changed

+46
-69
lines changed

3 files changed

+46
-69
lines changed

pyproject.toml

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
[tool.pytest.ini_options]
22
markers = [
33
"incremental: Mark tests as incremental",
4-
"kubevirt: Mark tests as kubevirt tests"
4+
"kubevirt: Mark tests as kubevirt tests",
55
]
66
addopts = [
77
"--pdbcls=IPython.terminal.debugger:TerminalPdb",
88
"--cov-config=pyproject.toml",
99
"--cov-report=html",
1010
"--cov-report=term",
11-
"--cov=ocp_resources"
11+
"--cov=ocp_resources.resource",
12+
"--cov=ocp_resources.utils.resource_constants",
13+
"--cov=ocp_resources.utils.constants",
14+
"--cov=ocp_resources.utils.utils",
15+
"--cov=ocp_resources.exceptions",
16+
"--cov=class_generator",
1217
]
1318

1419
[tool.coverage.run]
15-
omit = [ "tests/*" ]
20+
omit = ["tests/*", "class_generator/tests/*", "class_generator/scripts/tests/*"]
1621

1722
[tool.coverage.report]
23+
fail_under = 45
1824
skip_empty = true
1925

2026
[tool.coverage.html]
@@ -26,19 +32,19 @@ line-length = 120
2632
fix = true
2733
output-format = "grouped"
2834

29-
[tool.ruff.format]
30-
exclude = [ ".git", ".venv", ".mypy_cache", ".tox", "__pycache__" ]
35+
[tool.ruff.format]
36+
exclude = [".git", ".venv", ".mypy_cache", ".tox", "__pycache__"]
3137

3238
[tool.mypy]
3339
no_implicit_optional = true
3440
show_error_codes = true
3541
warn_unused_ignores = true
3642

3743
[tool.hatch.build.targets.wheel]
38-
packages = [ "ocp_resources", "class_generator" ]
44+
packages = ["ocp_resources", "class_generator"]
3945

4046
[tool.uv]
41-
dev-dependencies = [ "ipdb>=0.13.13", "ipython>=8.12.3" ]
47+
dev-dependencies = ["ipdb>=0.13.13", "ipython>=8.12.3"]
4248

4349
[project]
4450
requires-python = ">=3.9"
@@ -47,10 +53,10 @@ version = "11.0.24"
4753
description = "Wrapper around https://github.com/kubernetes-client/python"
4854
readme = "README.md"
4955
license = "Apache-2.0"
50-
keywords = [ "Openshift", "Kubevirt", "Openshift Virtualization" ]
56+
keywords = ["Openshift", "Kubevirt", "Openshift Virtualization"]
5157
classifiers = [
5258
"Programming Language :: Python :: 3",
53-
"Operating System :: OS Independent"
59+
"Operating System :: OS Independent",
5460
]
5561
dependencies = [
5662
"click>=8.1.7",
@@ -70,34 +76,34 @@ dependencies = [
7076
"ruff>=0.6.9",
7177
"testcontainers>=4.9.0",
7278
"timeout-sampler>=0.0.46",
73-
"xmltodict>=0.13.0"
79+
"xmltodict>=0.13.0",
7480
]
7581

76-
[[project.authors]]
77-
name = "Meni Yakove"
78-
82+
[[project.authors]]
83+
name = "Meni Yakove"
84+
7985

80-
[[project.authors]]
81-
name = "Ruth Netser"
82-
86+
[[project.authors]]
87+
name = "Ruth Netser"
88+
8389

84-
[[project.maintainers]]
85-
name = "Meni Yakove"
86-
90+
[[project.maintainers]]
91+
name = "Meni Yakove"
92+
8793

88-
[[project.maintainers]]
89-
name = "Ruth Netser"
90-
94+
[[project.maintainers]]
95+
name = "Ruth Netser"
96+
9197

92-
[project.urls]
93-
homepage = "https://github.com/RedHatQE/openshift-python-wrapper"
94-
documentation = "https://openshift-python-wrapper.readthedocs.io/en/latest/"
95-
Download = "https://pypi.org/project/openshift-python-wrapper/"
96-
"Bug Tracker" = "https://github.com/RedHatQE/openshift-python-wrapper/issues"
98+
[project.urls]
99+
homepage = "https://github.com/RedHatQE/openshift-python-wrapper"
100+
documentation = "https://openshift-python-wrapper.readthedocs.io/en/latest/"
101+
Download = "https://pypi.org/project/openshift-python-wrapper/"
102+
"Bug Tracker" = "https://github.com/RedHatQE/openshift-python-wrapper/issues"
97103

98-
[project.scripts]
99-
class-generator = "class_generator.class_generator:main"
104+
[project.scripts]
105+
class-generator = "class_generator.class_generator:main"
100106

101107
[build-system]
102-
requires = [ "hatchling" ]
108+
requires = ["hatchling"]
103109
build-backend = "hatchling.build"

tests/test_resources.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import pytest
22
import yaml
3+
from docker.errors import DockerException
34
import kubernetes
45
from testcontainers.k3s import K3SContainer
56

@@ -10,7 +11,7 @@
1011
from ocp_resources.secret import Secret
1112

1213

13-
class TestSecretExit(Secret):
14+
class SecretTestExit(Secret):
1415
def deploy(self, wait: bool = False):
1516
return self
1617

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

2122
@pytest.fixture(scope="session")
2223
def client():
23-
with K3SContainer() as k3s:
24-
yield get_client(config_dict=yaml.safe_load(k3s.config_yaml()))
24+
try:
25+
with K3SContainer() as k3s:
26+
yield get_client(config_dict=yaml.safe_load(k3s.config_yaml()))
27+
except DockerException:
28+
pytest.skip("K3S container not available")
2529

2630

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

103107
def test_resource_context_manager_exit(self, client):
104108
with pytest.raises(ResourceTeardownError):
105-
with TestSecretExit(name="test-context-manager-exit", namespace="default", client=client):
109+
with SecretTestExit(name="test-context-manager-exit", namespace="default", client=client):
106110
pass
107111

108112
def test_proxy_enabled_but_no_proxy_set(self, monkeypatch):

tox.toml

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,7 @@
11
skipsdist = true
2-
env_list = [
3-
"validate-resources",
4-
"validate-resources-script",
5-
"class-generator",
6-
"resource-tests",
7-
"api-group-order",
8-
"validate-unittests",
9-
]
10-
11-
[env.resource-tests]
12-
description = "Run resource tests on local cluster (k3d)"
13-
passenv = ["KUBECONFIG"]
14-
deps = ["uv"]
15-
commands = [["uv", "run", "pytest", "tests/test_resources.py"]]
16-
17-
[env.validate-resources]
18-
description = "Run validation resources tests"
19-
deps = ["uv"]
20-
commands = [["uv", "run", "pytest", "tests/test_validate_resources.py"]]
21-
22-
[env.validate-resources-script]
23-
description = "Run validation resources script tests (test the script itself, not the resources)"
24-
deps = ["uv"]
25-
commands = [["uv", "run", "pytest", "tests/test_validate_resources_script.py"]]
26-
27-
[env.class-generator]
28-
description = "Run class generator tests"
29-
deps = ["uv"]
30-
commands = [["uv", "run", "pytest", "class_generator/"]]
31-
32-
[env.api-group-order]
33-
description = "Run API group order tests"
34-
deps = ["uv"]
35-
commands = [["uv", "run", "pytest", "tests/test_api_group_order.py"]]
2+
env_list = ["unittests"]
363

374
[env.unittests]
385
description = "Run unittests"
396
deps = ["uv"]
40-
commands = [["uv", "run", "pytest", "tests/test_unittests.py", "-svv"]]
7+
commands = [["uv", "run", "pytest"]]

0 commit comments

Comments
 (0)