Skip to content

Commit a602442

Browse files
committed
K8SPSMDB-1192: Introduce e2e-test pytest wrapper
1 parent 3db09f5 commit a602442

File tree

5 files changed

+361
-0
lines changed

5 files changed

+361
-0
lines changed

.github/workflows/e2e-py-check.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: E2E Python Quality Check
2+
3+
on:
4+
push:
5+
paths:
6+
- 'e2e-tests/**/*.py'
7+
pull_request:
8+
paths:
9+
- 'e2e-tests/**/*.py'
10+
11+
jobs:
12+
quality-check:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
19+
- name: Install uv
20+
uses: astral-sh/setup-uv@v3
21+
22+
- name: Set up Python
23+
run: uv python install 3.13
24+
25+
- name: Install dependencies
26+
run: uv sync
27+
28+
- name: Run ruff check
29+
run: uv run ruff check e2e-tests/
30+
31+
- name: Run mypy
32+
run: uv run mypy e2e-tests/

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,3 +189,6 @@ bin/
189189
projects/
190190
installers/olm/operator_*.yaml
191191
installers/olm/bundles
192+
193+
# Test Reports
194+
e2e-tests/reports/

e2e-tests/test_pytest_wrapper.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import os
2+
import subprocess
3+
from pathlib import Path
4+
from typing import List, Tuple
5+
6+
import pytest
7+
8+
9+
def get_bash_tests() -> List[Tuple[str, Path]]:
10+
"""Find all bash test scripts in the same directory as this test file"""
11+
current_dir = Path(__file__).parent
12+
bash_tests: List[Tuple[str, Path]] = []
13+
14+
for test_dir in current_dir.iterdir():
15+
if test_dir.is_dir():
16+
run_script = test_dir / "run"
17+
if run_script.exists():
18+
bash_tests.append((test_dir.name, run_script))
19+
20+
return bash_tests
21+
22+
23+
bash_tests = get_bash_tests()
24+
25+
26+
@pytest.mark.parametrize(
27+
"test_name,script_path", bash_tests, ids=[name for name, _ in bash_tests]
28+
)
29+
def test_e2e(test_name: str, script_path: Path) -> None:
30+
"""Run bash script and check exit code"""
31+
32+
original_cwd: str = os.getcwd()
33+
script_dir: Path = script_path.parent
34+
35+
try:
36+
os.chdir(script_dir)
37+
result: subprocess.CompletedProcess[str] = subprocess.run(
38+
["bash", "run"], capture_output=True, text=True
39+
)
40+
41+
if result.returncode != 0:
42+
print(f"\nSTDOUT:\n{result.stdout}")
43+
print(f"\nSTDERR:\n{result.stderr}")
44+
45+
k8s_result: subprocess.CompletedProcess[str] = subprocess.run(
46+
["kubectl", "get", "nodes"], capture_output=True, text=True
47+
)
48+
print(f"\nK8s LOGS:\n{k8s_result.stdout}")
49+
50+
assert result.returncode == 0, (
51+
f"Test {test_name} failed with exit code {result.returncode}"
52+
)
53+
54+
finally:
55+
os.chdir(original_cwd)

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[project]
2+
name = "psmdb-pytest"
3+
version = "0.1.0"
4+
description = "Tests for PSMDB Operator"
5+
requires-python = ">=3.13"
6+
dependencies = [
7+
"mypy>=1.16.0",
8+
"pytest>=8.4.0",
9+
"pytest-html>=4.1.1",
10+
"pytest-json-report>=1.5.0",
11+
"pyyaml>=6.0.2",
12+
"ruff>=0.11.12",
13+
]
14+
15+
[tool.pytest.ini_options]
16+
addopts = "--html=e2e-tests/reports/report.html --self-contained-html --json-report --json-report-file=e2e-tests/reports/report.json --junitxml=e2e-tests/reports/report.xml"

0 commit comments

Comments
 (0)