我想测试 raise,但是在将 pytest 导入
Unable to import 'pytest'PylintE0401:import-error
时得到 test_main.py
。
我的环境和编辑器已正确配置并安装了 pytest。
重现步骤:
pipenv
创建环境:❯ pipenv --version
pipenv, version 2023.10.24
❯ pipenv shell
❯ pipenv --venv
/user/path/.local/share/virtualenvs/environment-name
❯ which python3
/user/path/.local/share/virtualenvs/environment-name/bin/python3
pipenv install --dev pytest
❯ pipenv graph
...
pytest==7.4.4
├── iniconfig [required: Any, installed: 2.0.0]
├── packaging [required: Any, installed: 23.2]
└── pluggy [required: >=0.12,<2.0, installed: 1.3.0]
pytest
[dev-packages]
pytest = "*"
test_main.py
import pytest
def test_zero_division():
with pytest.raises(ZeroDivisionError):
1 / 0
我错过了什么吗?
非常感谢任何帮助。
尝试使用此命令运行您的
test_main.py
pipenv run python test_main.py
文档:https://pipenv.pypa.io/en/latest/installation.html#using-installed-packages