Ошибки PyTest

Содержание
ImportError while importing test module
NameError: name 'pytest' is not defined
Похожие статьи

ImportError while importing test module

========================================================= test session starts ========================================================== platform linux -- Python 3.9.5, pytest-7.0.1, pluggy-1.0.0 rootdir: /home/andrei/python/pytest/app/tests collected 0 items / 1 error ================================================================ ERRORS ================================================================ ____________________________________________________ ERROR collecting test_psum.py _____________________________________________________ ImportError while importing test module '/home/andrei/python/pytest/app/tests/test_psum.py'. Hint: make sure your test modules/packages have valid Python names. Traceback: ../../../../.pyenv/versions/3.9.5/lib/python3.9/importlib/__init__.py:127: in import_module return _bootstrap._gcd_import(name[level:], package, level) /home/andrei/python/pytest/qa2/tests/test_psum.py:1: in ??? E ModuleNotFoundError: No module named 'psum' ======================================================= short test summary info ======================================================== ERROR test_psum.py !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! =========================================================== 1 error in 0.06s ===========================================================

Такая ошибка может возникнуть если тест лежит в одтельной директории, например tests, и запущен оттуда же, но импорт тестируемого модуля сделан самым простым способом - просто как from mod1 import fun1

PyTest не может найти модуль, который нужно протестировать. Скорее всего поможет запуск теста из корневой директории.

То есть вместо

python -m pytest test_something.py

Выполните

cd ..
python -m pytest tests/test_something.py

NameError: name 'pytest' is not defined

Нужно импортировать pytest.

import pytest

Похожие статьи
PyTest
Тестирование
Видео
Python