the `pytest.config` global is deprecated. Please use `request.config` or `pytest_configure`
时间: 2023-10-24 10:08:29 浏览: 45
the `pytest.config` global is deprecated. Please use `request.config` or `pytest_configure`.
在最新版本的pytest中,`pytest.config`全局变量已被弃用。相反,建议使用`request.config`或`pytest_configure`。这是因为`pytest.config`被认为是一个不必要的全局变量,并且不符合良好的软件工程实践。`request.config`是一个该变量的替代方案,可以提供与`pytest.config`相同的功能,并且更具可读性和灵活性。
相关问题
module '_pytest.runner' has no attribute 'main'
该错误通常发生在引用的模块中没有名称为`main`的属性时。可以通过在执行模块时添加`-m`选项来解决此问题,例如:`python -m unittest test_module.py`。这将直接执行模块而不是导入模块并在之后执行。
另外,如果您使用的是Pytest框架,也可以使用以下命令运行测试:
```shell
pytest test_module.py
```
范例:<<引用:在使用unittest模块时,如果在执行测试文件时出现了AttributeError: module '__main__' has no attribute...错误,可以通过使用 unittest.main(argv=['first-arg-is-ignored'],exit=False) 来解决问题。[^1]。引用:在使用Pytest测试框架时,如果出现module '_pytest.runner' has no attribute 'main'错误,可以使用 pytest 来运行测试。。
_pytest.pathlib.ImportPathMismatchError
这个错误通常是由于在运行pytest时,导入模块的路径与pytest的当前工作路径不匹配。可以尝试在运行pytest时加上参数`--import-mode=append`,这将允许pytest在导入模块时搜索父级目录。或者,可以将导入模块的路径添加到PYTHONPATH环境变量中,以使pytest能够找到它们。