I want to test for raise, but getting Unable to import 'pytest'PylintE0401:import-error when importing pytest into test_main.py.
My environment and editor are correctly configured and pytest installed.
Steps to reproduce:
- Created environment with
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
- Correctly configured my editor to use the created virtual environment
- Installed
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]
- Pipfile contains
pytest
[dev-packages]
pytest = "*"
- Contents of
test_main.py
import pytest
def test_zero_division():
with pytest.raises(ZeroDivisionError):
1 / 0
Am I missing something?
Any help is very much appreciated.
Try to run your
test_main.pywith this commandpipenv run python test_main.pyDoc: https://pipenv.pypa.io/en/latest/installation.html#using-installed-packages