Skip to content

Commit 5ffa2d9

Browse files
committed
Convert the test suite into a Python package
Move the tests/ directory inside the lightspeed-tests Python package and add a CLI entrypoint for running the tests.
1 parent 951f3f2 commit 5ffa2d9

16 files changed

Lines changed: 73 additions & 51 deletions

‎README.md‎

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,40 @@
22

33
Test suite for RHOS Lightspeed in RHOSO environments.
44

5-
## Setup
5+
## Installation
6+
7+
Python 3.12 is required. Install from a cloned repo:
68

79
```bash
8-
uv venv
9-
uv sync
10+
uv sync --python 3.12
11+
source .venv/bin/activate
1012
```
1113

12-
## Configuration
13-
14-
Configure the service in `config/default.yaml`. For Goose API tests, set
15-
`goose.model` to the value of the Goose container's `LIGHTSPEED_MODEL`:
14+
Or install the standalone command directly from GitHub:
1615

17-
```yaml
18-
rhos_lightspeed:
19-
base_url: "http://localhost:8080"
20-
timeout: 30
16+
```bash
17+
uv tool install --python 3.12 git+https://github.com/openstack-k8s-operators/lightspeed-tests.git
18+
```
2119

22-
query:
23-
default_question: "What is OpenStack?"
20+
The package includes the tests and their default configuration. Once installed,
21+
`lightspeed-tests` works from any directory. `lightspeed-test` is also available
22+
as an alias.
2423

25-
goose:
26-
model: "<same value as Goose LIGHTSPEED_MODEL>"
27-
```
24+
## Configuration
2825

29-
Supply the bearer token through the environment:
26+
The tests load the default config from `src/rhos_lightspeed_tests/default.yaml`.
27+
Configure the service through environment variables:
3028

3129
```bash
30+
export RHOS_LIGHTSPEED_URL="https://localhost:8443"
3231
export RHOS_LIGHTSPEED_TOKEN="<Lightspeed bearer token>"
32+
export RHOS_LIGHTSPEED_MODEL="<same value as Goose LIGHTSPEED_MODEL>"
3333
```
3434

3535
`RHOS_LIGHTSPEED_URL` and `RHOS_LIGHTSPEED_MODEL` can override the URL and model
36-
from the config file. Use a service origin without `/v1`. With the test-operator
37-
playbook, supply `lightspeed_model`.
36+
from the default config. Use a service origin without `/v1`. With the test-operator
37+
playbook, supply `lightspeed_model`. For Goose API tests, set the model to the Goose
38+
container's `LIGHTSPEED_MODEL` value.
3839

3940
If you run the tests outside of OpenShift, you need to have a running port forward
4041
for the `lightspeed-app-server` service. For example:
@@ -45,29 +46,38 @@ oc port-forward -n openstack-lightspeed svc/lightspeed-app-server 8443:8443
4546

4647
## Running tests
4748

49+
The command accepts pytest options and returns pytest's exit status. In a uv
50+
checkout, prefix the commands below with `uv run`.
51+
4852
```bash
4953
# Run all tests
50-
uv run pytest
54+
lightspeed-tests
5155

5256
# Run integration tests only
53-
uv run pytest tests/integration/
57+
lightspeed-tests -k integration
5458

5559
# Run Goose API tests
56-
uv run pytest tests/integration/test_goose_responses.py
60+
lightspeed-tests -k goose
5761

5862
# Skip Goose tests that require a real LLM's answer content
59-
uv run pytest tests/integration/test_goose_responses.py -m "not llm_dependent"
63+
lightspeed-tests -k goose -m "not llm_dependent"
64+
65+
# Verify test discovery without contacting a service
66+
lightspeed-tests --collect-only
6067

61-
# Generate JUnit XML (automatic via pyproject.toml config)
62-
uv run pytest # outputs test-results.xml
68+
# Enable verbose output and generate a JUnit XML report
69+
lightspeed-tests -v --junitxml=results.xml
6370
```
6471

72+
Integration tests require a deployed Lightspeed service. Goose tests also
73+
require a configured model.
74+
6575
## Adding tests
6676

6777
1. Create test file in appropriate directory:
68-
- `tests/unit/` - Fast, isolated tests
69-
- `tests/integration/` - Tests requiring deployed service
70-
- `tests/e2e/` - Full end-to-end scenarios
78+
- `src/rhos_lightspeed_tests/tests/unit/` - Fast, isolated suite tests
79+
- `src/rhos_lightspeed_tests/tests/integration/` - Tests requiring deployed service
80+
- `src/rhos_lightspeed_tests/tests/e2e/` - Full end-to-end scenarios
7181

7282
2. Use the shared fixtures from `conftest.py`:
7383
```python
@@ -77,24 +87,24 @@ uv run pytest # outputs test-results.xml
7787
assert response.status_code == 200
7888
```
7989

80-
3. Run: `uv run pytest tests/integration/test_my_feature.py`
90+
3. Run: `uv run lightspeed-tests -k test_my_feature`
91+
92+
Build a source distribution and wheel with `uv build`.
8193

8294
## Project structure
8395

8496
```
8597
rhos-lightspeed-tests/
86-
├── config/
87-
│ └── default.yaml # Default test configuration
88-
├── src/rhos_lightspeed_tests/ # Shared utilities
89-
│ ├── __init__.py
98+
├── src/rhos_lightspeed_tests/ # Installed package
99+
│ ├── __init__.py # lightspeed-tests entry point
90100
│ ├── client.py # API client (query, health)
91-
│ └── config.py # Reads default.yaml, env var overrides
92-
├── tests/
93-
│ ├── conftest.py # Shared fixtures (config, client)
94-
│ ├── unit/
95-
│ ├── integration/
96-
│ │ └── test_query_endpoint.py # First test: /query endpoint
97-
│ └── e2e/
101+
│ ├── config.py # Loads defaults and environment overrides
102+
│ ├── default.yaml # Bundled default configuration
103+
│ └── tests/
104+
│ ├── conftest.py # Shared fixtures (config, client)
105+
│ ├── unit/
106+
│ ├── integration/
107+
│ └── e2e/
98108
├── pyproject.toml
99109
└── README.md
100110
```

‎playbooks/README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Ansible playbooks to run the test suite.
44

55
## `run_lightspeed_tests.yaml`
66

7-
Executes the RHOS Lightspeed test suite using pytest. The playbook:
7+
Executes the RHOS Lightspeed test suite using `lightspeed-tests`. The playbook:
88

99
1. Installs the [uv](https://astral.sh/uv) package manager if not already available
1010
2. Installs Python 3.12 using uv
1111
3. Verifies the test suite directory exists (cloned by test-operator)
1212
4. Reads the Kubernetes service account token for authentication
1313
5. Installs Python dependencies using uv
14-
6. Runs the pytest test suite with configurable arguments
14+
6. Runs `lightspeed-tests` with configurable pytest arguments
1515
7. Generates JUnit XML test results for reporting
1616

1717
Test results are stored in the location specified by `junit_xml_path`, which the test-operator can consume for reporting.

‎playbooks/run_lightspeed_tests.yaml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@
9797
PYTHONUNBUFFERED: "1"
9898
PATH: "{{ ansible_env.HOME }}/.local/bin:{{ ansible_env.PATH }}"
9999

100-
- name: Run pytest tests
100+
- name: Run Lightspeed tests
101101
ansible.builtin.command:
102102
cmd: >
103-
{{ ansible_env.HOME }}/.local/bin/uv run pytest
103+
{{ ansible_env.HOME }}/.local/bin/uv run lightspeed-tests
104104
{{ pytest_args }}
105105
--junitxml={{ junit_xml_path }}
106106
chdir: "{{ test_suite_path }}"

‎pyproject.toml‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ dependencies = [
1212
"pyyaml>=6.0.0",
1313
]
1414

15+
[project.scripts]
16+
lightspeed-tests = "rhos_lightspeed_tests:main"
17+
lightspeed-test = "rhos_lightspeed_tests:main"
18+
1519
[dependency-groups]
1620
dev = [
1721
"ruff>=0.16.1",
@@ -25,7 +29,7 @@ requires = ["uv_build>=0.12.3,<0.13"]
2529
build-backend = "uv_build"
2630

2731
[tool.pytest.ini_options]
28-
testpaths = ["tests"]
32+
testpaths = ["src/rhos_lightspeed_tests/tests"]
2933
addopts = "--verbose --junitxml=test-results.xml"
3034
python_files = "test_*.py"
3135
python_functions = "test_*"
@@ -41,4 +45,4 @@ target-version = "py312"
4145
extend-select = ["S"]
4246

4347
[tool.ruff.lint.per-file-ignores]
44-
"tests/**/*.py" = ["S101"]
48+
"src/rhos_lightspeed_tests/tests/**/*.py" = ["S101"]
Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,11 @@
1-
"""RHOS Lightspeed test utilities."""
1+
"""RHOS Lightspeed test suite and shared utilities."""
2+
3+
import sys
4+
5+
import pytest
6+
7+
8+
def main() -> int:
9+
"""Run the bundled tests, forwarding arguments and pytest's exit status."""
10+
# --pyargs finds the tests in the installed Python package.
11+
return pytest.main(["--pyargs", "rhos_lightspeed_tests.tests", *sys.argv[1:]])

‎src/rhos_lightspeed_tests/config.py‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
import yaml
77

8-
DEFAULT_CONFIG_PATH = (
9-
Path(__file__).resolve().parent.parent.parent / "config" / "default.yaml"
10-
)
8+
DEFAULT_CONFIG_PATH = Path(__file__).with_name("default.yaml")
119

1210

1311
def load_config(config_path: str | None = None) -> dict:

tests/__init__.py renamed to src/rhos_lightspeed_tests/tests/__init__.py

File renamed without changes.

tests/conftest.py renamed to src/rhos_lightspeed_tests/tests/conftest.py

File renamed without changes.

tests/e2e/__init__.py renamed to src/rhos_lightspeed_tests/tests/e2e/__init__.py

File renamed without changes.

0 commit comments

Comments
 (0)