|
1 | 1 | # Overview |
| 2 | + |
2 | 3 | This is a testing repo for OpenDataHub and OpenShift AI, which are MLOps platforms for OpenShift. |
3 | | -The tests contained in the repo are high-level integration tests at the Kubernetes API level. |
4 | | - |
5 | | -# Documentation |
6 | | -All the general information about the repo is contained in the /docs directory. |
7 | | -At the start of each session, consider if you need to consult any of these files in order to answer: |
8 | | -- [Guidelines for Getting Started](./docs/GETTING_STARTED.md) |
9 | | -- [Developer Guide](./docs/DEVELOPER_GUIDE.md) |
10 | | -- [Style Guide](./docs/STYLE_GUIDE.md) |
11 | | - |
12 | | -# Specific Instructions |
13 | | -- Avoid unnecessary complexity: Aim for the simplest solution that works, while keeping the code clean. |
14 | | -- Avoid obvious comments: Only add comments to explain especially complex code blocks. |
15 | | -- Maintain code consistency: Follow existing code patterns and architecture. |
16 | | -- Maintain locality of behavior: Keep code close to where it's used. |
17 | | -- Make small, focused changes, unless explicitly asked otherwise. |
18 | | -- Keep security in mind: Avoid filtering sensitive information and running destructive commands. |
19 | | -- When in doubt about something, ask the user. |
| 4 | +The tests are high-level integration tests at the Kubernetes API level. |
| 5 | + |
| 6 | +You are an expert QE engineer writing maintainable pytest tests that other engineers can understand without deep domain knowledge. |
| 7 | + |
| 8 | +## Commands |
| 9 | + |
| 10 | +### Validation (run before committing) |
| 11 | +```bash |
| 12 | +# Run all pre-commit checks |
| 13 | +pre-commit run --all-files |
| 14 | + |
| 15 | +# Run tox (CI validation) |
| 16 | +tox |
| 17 | +``` |
| 18 | + |
| 19 | +### Test Execution |
| 20 | +```bash |
| 21 | +# Collect tests without running (verify structure) |
| 22 | +uv run pytest --collect-only |
| 23 | + |
| 24 | +# Run specific marker |
| 25 | +uv run pytest -m smoke |
| 26 | +uv run pytest -m "model_serving and tier1" |
| 27 | + |
| 28 | +# Run with setup plan (debug fixtures) |
| 29 | +uv run pytest --setup-plan tests/model_serving/ |
| 30 | +``` |
| 31 | + |
| 32 | +## Project Structure |
| 33 | + |
| 34 | +``` |
| 35 | +tests/ # Test modules by component |
| 36 | +├── conftest.py # Shared fixtures (session/class scope) |
| 37 | +├── fixtures/ # Extracted fixture modules |
| 38 | +├── <component>/ # Component test directories |
| 39 | +│ ├── conftest.py # Component-scoped fixtures |
| 40 | +│ └── test_*.py # Test files |
| 41 | +utilities/ # Shared utility functions |
| 42 | +├── manifests/ # Runtime manifests and configs |
| 43 | +└── <topic>_utils.py # Topic-specific utilities |
| 44 | +``` |
| 45 | + |
| 46 | +## Essential Patterns |
| 47 | + |
| 48 | +### Tests |
| 49 | +- Every test MUST have a docstring explaining what it tests (see `tests/cluster_health/test_cluster_health.py`) |
| 50 | +- Apply relevant markers from `pytest.ini`: tier (`smoke`, `sanity`, `tier1`, `tier2`), component (`model_serving`, `model_registry`, `llama_stack`), infrastructure (`gpu`, `parallel`, `slow`) |
| 51 | +- Use Given-When-Then format in docstrings for behavioral clarity |
| 52 | + |
| 53 | +### Fixtures |
| 54 | +- Fixture names MUST be nouns: `storage_secret` not `create_secret` |
| 55 | +- Use context managers for resource lifecycle (see `tests/conftest.py:544-550` for pattern) |
| 56 | +- Fixtures do one thing only—compose them rather than nesting |
| 57 | +- Use narrowest scope that meets the need: function > class > module > session |
| 58 | + |
| 59 | +### Kubernetes Resources |
| 60 | +- Use [openshift-python-wrapper](https://github.com/RedHatQE/openshift-python-wrapper) for all K8s API calls |
| 61 | +- Resource lifecycle MUST use context managers to ensure cleanup |
| 62 | +- Use `oc` CLI only when wrapper is not relevant (e.g., must-gather) |
| 63 | + |
| 64 | +## Common Pitfalls |
| 65 | + |
| 66 | +- **ERROR vs FAILED**: Pytest reports fixture failures as ERROR, test failures as FAILED |
| 67 | +- **Heavy imports**: Don't import heavy resources at module level; defer to fixture scope |
| 68 | +- **Flaky tests**: Use `pytest.skip()` with `@pytest.mark.jira("PROJ-123")`, never delete |
| 69 | +- **Fixture scope**: Session fixtures in `tests/conftest.py` run once for entire suite—modify carefully |
| 70 | + |
| 71 | +## Boundaries |
| 72 | + |
| 73 | +### ✅ Always |
| 74 | +- Follow existing patterns before introducing new approaches |
| 75 | +- Add type annotations (mypy strict enforced) |
| 76 | +- Write Google-format docstrings for tests and fixtures |
| 77 | +- Run `pre-commit run --all-files` before suggesting changes |
| 78 | + |
| 79 | +### ⚠️ Ask First |
| 80 | +- Adding new dependencies to `pyproject.toml` |
| 81 | +- Creating new `conftest.py` files |
| 82 | +- Moving fixtures to shared locations |
| 83 | +- Adding new markers to `pytest.ini` |
| 84 | +- Modifying session-scoped fixtures |
| 85 | + |
| 86 | +### 🚫 Never |
| 87 | +- Remove or modify existing tests without explicit request |
| 88 | +- Add code that isn't immediately used (YAGNI) |
| 89 | +- Log secrets, tokens, or credentials |
| 90 | +- Skip pre-commit or type checking |
| 91 | +- Create abstractions for single-use code |
| 92 | + |
| 93 | +## Documentation Reference |
| 94 | + |
| 95 | +Consult these for detailed guidance: |
| 96 | +- [Constitution](./CONSTITUTION.md) - Non-negotiable principles (supersedes all other docs) |
| 97 | +- [Developer Guide](./docs/DEVELOPER_GUIDE.md) - Contribution workflow, fixture examples |
| 98 | +- [Style Guide](./docs/STYLE_GUIDE.md) - Naming, typing, docstrings |
0 commit comments