# colcon test: Failed to find pytest framework for package 'my_package'

- **ID:** `ros2/colcon-test-no-pytest-framework`
- **Domain:** ros2
- **Category:** test_error
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

colcon test requires a test framework (pytest or unittest) to be configured in setup.cfg or package.xml; missing or misconfigured entry causes test discovery failure.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| ros2:humble | active | — | — |
| ros2:iron | active | — | — |
| colcon-core:0.14.0 | active | — | — |
| pytest:7.4.0 | active | — | — |

## Workarounds

1. **Ensure setup.cfg in the package root contains a [tool:pytest] section and test paths are listed. Example:
[tool:pytest]
testpaths = test

Then run: colcon test --packages-select my_package** (85% success)
   ```
   Ensure setup.cfg in the package root contains a [tool:pytest] section and test paths are listed. Example:
[tool:pytest]
testpaths = test

Then run: colcon test --packages-select my_package
   ```
2. **Add a test_depend entry for pytest in package.xml and ensure a conftest.py or __init__.py exists in the test directory:
<test_depend>python3-pytest</test_depend>

Then rebuild: colcon build --packages-select my_package && colcon test** (80% success)
   ```
   Add a test_depend entry for pytest in package.xml and ensure a conftest.py or __init__.py exists in the test directory:
<test_depend>python3-pytest</test_depend>

Then rebuild: colcon build --packages-select my_package && colcon test
   ```

## Dead Ends

- **Reinstalling pytest with pip without checking package configuration** — pytest is already installed; the issue is in the package's test configuration, not the framework itself. (70% fail)
- **Adding a dummy test file without updating setup.cfg** — colcon uses setup.cfg or package.xml to discover tests; a test file alone is insufficient. (85% fail)
- **Running pytest directly instead of colcon test** — pytest may work locally but colcon test uses a different discovery mechanism; this doesn't fix the colcon integration. (60% fail)
