Удалённый запуск тестов PyTest

Содержание
Введение
Установка
Пример
Похожие статьи

Введение

В этой статье вы можете познакомиться с созданием отчёта в виде html файла с помощью pytest-html

Установка

python -m pip install pytest-html

Collecting pytest-html Downloading pytest_html-4.1.1-py3-none-any.whl.metadata (3.9 kB) Collecting jinja2>=3.0.0 (from pytest-html) Using cached jinja2-3.1.6-py3-none-any.whl.metadata (2.9 kB) Collecting pytest-metadata>=2.0.0 (from pytest-html) Downloading pytest_metadata-3.1.1-py3-none-any.whl.metadata (8.6 kB) Requirement already satisfied: pytest>=7.0.0 in c:\autotest\sandbox\python\venv\lib\site-packages (from pytest-html) (8.3.5) Collecting MarkupSafe>=2.0 (from jinja2>=3.0.0->pytest-html) Using cached markupsafe-3.0.3-cp312-cp312-win_amd64.whl.metadata (2.8 kB) Requirement already satisfied: colorama in c:\autotest\sandbox\python\venv\lib\site-packages (from pytest>=7.0.0->pytest-html) (0.4.6) Requirement already satisfied: iniconfig in c:\autotest\sandbox\python\venv\lib\site-packages (from pytest>=7.0.0->pytest-html) (2.0.0) Requirement already satisfied: packaging in c:\autotest\sandbox\python\venv\lib\site-packages (from pytest>=7.0.0->pytest-html) (24.2) Requirement already satisfied: pluggy<2,>=1.5 in c:\autotest\sandbox\python\venv\lib\site-packages (from pytest>=7.0.0->pytest-html) (1.5.0) Downloading pytest_html-4.1.1-py3-none-any.whl (23 kB) Using cached jinja2-3.1.6-py3-none-any.whl (134 kB) Using cached markupsafe-3.0.3-cp312-cp312-win_amd64.whl (15 kB) Downloading pytest_metadata-3.1.1-py3-none-any.whl (11 kB) Installing collected packages: MarkupSafe, pytest-metadata, jinja2, pytest-html Successfully installed MarkupSafe-3.0.3 jinja2-3.1.6 pytest-html-4.1.1 pytest-metadata-3.1.1

Пример

def test_pass(): assert 1 == 1 def test_fail(): assert 1 == 0

python -m pytest demo.py --html=reports\report.html -v

========================== test session starts ========================== platform win32 -- Python 3.12.2, pytest-8.3.5, pluggy-1.5.0 -- C:\pytest\venv\Scripts\python.exe cachedir: .pytest_cache metadata: {'Python': '3.12.2', 'Platform': 'Windows-11-10.0.22631-SP0', 'Packages': {'pytest': '8.3.5', 'pluggy': '1.5.0'}, 'Plugins': {'html': '4.1.1', 'metadata': '3.1.1'}} rootdir: C:\pytest plugins: html-4.1.1, metadata-3.1.1 collected 2 items demo.py::test_pass PASSED [ 50%] demo.py::test_fail FAILED [100%] ========================== FAILURES ========================= __________________________ test_fail ________________________ def test_fail(): > assert 1 == 0 E assert 1 == 0 demo.py:6: AssertionError --------- Generated html report: file:///C:/pytesst/reports/report.html ------- ========================== short test summary info ============================ FAILED demo.py::test_fail - assert 1 == 0 ========================== 1 failed, 1 passed in 0.08s ========================

Если директории reports не было - она будет создана автоматически.

Помимо самого файла report.html появится поддиректория assets, в которой будет файл style.css

pytest ├── demo.py └── reports ├── assets │ └── style.css └── report.html

Если теперь открыть файл report.html в директории reports то он будет выглядеть следующим оригинальным образом.

Отчёт созданный с помощью pytest-html изображение с сайта www.testsetup.ru
Отчёт
www.testsetup.ru

Автор статьи: Андрей Олегович

Похожие статьи
Основы
Параметризация
@fixture
conftest.py
Удалённый запуск
Ошибки
Видео

Поиск по сайту

Подпишитесь на Telegram канал @aofeed чтобы следить за выходом новых статей и обновлением старых

Перейти на канал

@aofeed

Задать вопрос в Телеграм-группе

@aofeedchat

Контакты и сотрудничество:
Рекомендую наш хостинг beget.ru
Пишите на info@urn.su если Вы:
1. Хотите написать статью для нашего сайта или перевести статью на свой родной язык.
2. Хотите разместить на сайте рекламу, подходящую по тематике.
3. Реклама на моём сайте имеет максимальный уровень цензуры. Если Вы увидели рекламный блок недопустимый для просмотра детьми школьного возраста, вызывающий шок или вводящий в заблуждение - пожалуйста свяжитесь с нами по электронной почте
4. Нашли на сайте ошибку, неточности, баг и т.д. ... .......
5. Статьи можно расшарить в соцсетях, нажав на иконку сети: