Skip to content

feat: fake k8 client and resource test generator #2433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 6, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ fcn_exclude_functions =
subprocess,
urlparse,
parse_qs,
self,
defaultdict,
add_row,

enable-extensions =
FCN,
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,37 @@ pre-commit install

Some code examples locate at [examples](examples) directory

## Adding Tests for New Resources

### Add tests

Generate automated tests for newly added resources using the test generator:

**Note**: Tests are only generated for classes that were generated by class-generator.

```bash
# Generate tests for a specific resource
uv run tests/scripts/generate_pytest_test.py --kind ResourceName

# Generate tests for multiple resources
uv run tests/scripts/generate_pytest_test.py --kind Pod,Service,Deployment

# Preview generated tests without writing files
uv run tests/scripts/generate_pytest_test.py --kind ResourceName --dry-run
```

The generator creates standard CRUD tests in `tests/test_resources/test_resource_name.py` using the fake client for isolated testing without requiring a real Kubernetes cluster.

Run the generated tests:

```bash
# Run tests for specific resource
uv run --group tests pytest tests/test_resources/test_resource_name.py

# Run all resource tests
uv run --group tests pytest tests/test_resources/
```

## Contribute to the project

To contribute new additions or changes to the project, please refer to the [contribution guide](CONTRIBUTING.md) first.
Loading