Keboola Component Tester
Testing approach
Three levels, in priority order:
- Datadir tests — functional tests using KBC_DATADIR structure; the primary method for all components
- Unit tests — isolated logic tests for transformations, validation, config parsing
- VCR functional tests — for components that call external HTTP APIs (preferred over manual mocks for extractors/writers)
Choosing VCR vs mocks
Use VCR (keboola.datadirtest) when the component makes external HTTP calls:
- Records real API interactions once → replays deterministically in CI without credentials
- More realistic than hand-rolled mocks; catches API contract changes
- Required for extractors; recommended for writers that call external APIs
Use mocks (unittest.mock) when:
- Testing pure logic, transformation, or validation code
- Writing unit tests for individual functions
- The component has no HTTP calls (applications, pure transformations)
VCR setup workflow
- Add
keboola.datadirtest>=2.0.0 to pyproject.toml dev dependencies, run uv sync -U
- Copy
tests/test_functional.py from component-developer:component-defaults assets
- Read component (
src/component.py, src/configuration.py, component_config/configSchema.json) and build tests/setup/configs.json — see vcr-configs-format.md
- For authenticated APIs: ask user for real credentials →
secrets.json (verify it's in .gitignore)
- Scaffold to record:
uv run python -m keboola.datadirtest scaffold [--secrets secrets.json] [--chain-state]
- Check cassettes for unsanitized dynamic values — see vcr-sanitizers.md
- Update
.gitignore, Dockerfile (COPY tests/ tests), and push.yml (use python -m pytest)
- Verify:
python -m pytest locally and in Docker
See vcr-quickstart.md for all scaffold commands. See vcr-troubleshooting.md for common failures.
References
| File |
When to read |
references/datadir-tests.md |
Setting up datadir tests — directory structure, config.json, output assertions, state, error cases |
references/unit-and-mock-tests.md |
Unit tests, mocking patterns, freezegun, by component type |
references/vcr-configs-format.md |
Building configs.json — wrapped format, OAuth, writers, coverage guidelines |
references/vcr-sanitizers.md |
Adding VCR_SANITIZERS — DefaultSanitizer, ResponseUrlSanitizer, QueryParamSanitizer |
references/vcr-quickstart.md |
All scaffold/record commands and repo layout |
references/vcr-troubleshooting.md |
Common VCR failures and fixes |
references/vcr-debug-from-platform.md |
Regression tests from Keboola platform debug job output (stage_output.zip) |
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: keboola-ai-kit-test-component3description: Keboola Component Tester4---56# Keboola Component Tester78## Testing approach910Three levels, in priority order:11121. **Datadir tests** — functional tests using KBC_DATADIR structure; the primary method for all components132. **Unit tests** — isolated logic tests for transformations, validation, config parsing143. **VCR functional tests** — for components that call external HTTP APIs (preferred over manual mocks for extractors/writers)1516## Choosing VCR vs mocks1718**Use VCR** (`keboola.datadirtest`) when the component makes external HTTP calls:19- Records real API interactions once → replays deterministically in CI without credentials20- More realistic than hand-rolled mocks; catches API contract changes21- Required for extractors; recommended for writers that call external APIs2223**Use mocks** (`unittest.mock`) when:24- Testing pure logic, transformation, or validation code25- Writing unit tests for individual functions26- The component has no HTTP calls (applications, pure transformations)2728## VCR setup workflow29301. Add `keboola.datadirtest>=2.0.0` to `pyproject.toml` dev dependencies, run `uv sync -U`312. Copy `tests/test_functional.py` from `component-developer:component-defaults` assets323. Read component (`src/component.py`, `src/configuration.py`, `component_config/configSchema.json`) and build `tests/setup/configs.json` — see [vcr-configs-format.md](references/vcr-configs-format.md)334. For authenticated APIs: ask user for real credentials → `secrets.json` (verify it's in `.gitignore`)345. Scaffold to record: `uv run python -m keboola.datadirtest scaffold [--secrets secrets.json] [--chain-state]`356. Check cassettes for unsanitized dynamic values — see [vcr-sanitizers.md](references/vcr-sanitizers.md)367. Update `.gitignore`, `Dockerfile` (`COPY tests/ tests`), and `push.yml` (use `python -m pytest`)378. Verify: `python -m pytest` locally and in Docker3839See [vcr-quickstart.md](references/vcr-quickstart.md) for all scaffold commands. See [vcr-troubleshooting.md](references/vcr-troubleshooting.md) for common failures.4041## References4243| File | When to read |44|------|-------------|45| `references/datadir-tests.md` | Setting up datadir tests — directory structure, config.json, output assertions, state, error cases |46| `references/unit-and-mock-tests.md` | Unit tests, mocking patterns, freezegun, by component type |47| `references/vcr-configs-format.md` | Building configs.json — wrapped format, OAuth, writers, coverage guidelines |48| `references/vcr-sanitizers.md` | Adding VCR_SANITIZERS — DefaultSanitizer, ResponseUrlSanitizer, QueryParamSanitizer |49| `references/vcr-quickstart.md` | All scaffold/record commands and repo layout |50| `references/vcr-troubleshooting.md` | Common VCR failures and fixes |51| `references/vcr-debug-from-platform.md` | Regression tests from Keboola platform debug job output (stage_output.zip) |5253---54> Converted and distributed by [TomeVault](https://tomevault.io/claim/keboola) — claim your Tome and manage your conversions.55<!-- tomevault:4.0:skill_md:2026-04-11 -->