test_Bread.py::test ERROR [100%] test setup failed file /Users/zhangxiangyang/Downloads/Bread-main/test_Bread.py, line 127 def test(opt): E fixture 'opt' not found > available fixtures: anyio_backend, anyio_backend_name, anyio_backend_options, cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory > use 'pytest --fixtures [testpath]' for help on them.
时间: 2023-12-06 16:42:38 浏览: 50
这个错误提示是因为你在测试函数中使用了一个名为 `opt` 的 fixture,但是 pytest 没有找到这个 fixture。你需要在测试函数的参数中加上 `opt` 这个参数,并且在测试文件或者 conftest.py 中定义这个 fixture。你可以使用 `pytest.fixture()` 装饰器来定义 fixture。例如:
```python
import pytest
@pytest.fixture
def opt():
return {'key': 'value'}
def test_my_function(opt):
assert opt['key'] == 'value'
```
这样,`opt` fixture 就会被注入到 `test_my_function` 函数中,供测试使用。注意,fixture 的名称需要与测试函数中的参数名称相同。