# error: Multiple top-level packages discovered in a flat-layout: ['foo', 'tests'].

- **ID:** `python/setuptools-package-discovery-error`
- **Domain:** python
- **Category:** config_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

With setuptools' automatic package discovery, a flat project layout containing more than one top-level directory (e.g. the package and a `tests`/`docs` dir) is ambiguous, so setuptools refuses to guess.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 3.8 | active | — | — |
| 3.9 | active | — | — |
| 3.10 | active | — | — |
| 3.11 | active | — | — |
| 3.12 | active | — | — |

## Workarounds

1. **** (92% success)
   ```
   Declare packages explicitly in pyproject.toml: `[tool.setuptools.packages.find] include = ["foo*"] exclude = ["tests*"]`.
   ```
2. **** (90% success)
   ```
   Move the package into a `src/` layout and set `[tool.setuptools.packages.find] where = ["src"]`.
   ```

## Dead Ends

- **** — Loses test code and does not address the discovery ambiguity. (85% fail)
- **** — May still collide with other top-level dirs and is a cosmetic change. (70% fail)
