# pytest.PytestConfigWarning: 在 'tests/' 中未找到 conftest.py

- **ID:** `python/pytest-conftest-not-found`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

pytest期望在测试目录中存在conftest.py文件以共享fixture和钩子，但该文件缺失，如果测试依赖于conftest定义的fixture，可能会导致fixture解析失败。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 7.0.0 | active | — | — |
| 8.0.0 | active | — | — |

## 解决方案

1. **Create a proper conftest.py file with the necessary fixtures and hooks** (95% 成功率)
   ```
   In the tests/ directory, create conftest.py:
import pytest

@pytest.fixture
def shared_fixture():
    return 'data'
Then tests can use 'shared_fixture' without importing.
   ```
2. **Specify a custom conftest path using pytest's --confcutdir option** (70% 成功率)
   ```
   pytest --confcutdir=tests/ tests/
This tells pytest to look for conftest only in the tests/ directory.
   ```

## 无效尝试

- **Creating an empty conftest.py file without any content** — This suppresses the warning but does not provide the necessary fixtures, causing test failures later. (50% 失败率)
- **Moving all fixtures to each individual test file** — This duplicates code and reduces maintainability, but may resolve the immediate warning. (30% 失败率)
