0
0
PyTesttesting~10 mins

pytest-html for HTML reports - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the pytest-html plugin.

PyTest
import pytest

@pytest.mark.usefixtures([1])
def test_example():
    assert 1 == 1
Drag options to blanks, or click blank then click option'
Apytest_html
Bhtml
Cpytest_html_report
Dhtml_report
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect fixture names like 'html' or 'html_report' which do not exist.
2fill in blank
medium

Complete the command to generate an HTML report using pytest-html.

PyTest
pytest --[1]=report.html
Drag options to blanks, or click blank then click option'
Ahtmlpath
Bhtml
Chtml-report
Dhtmlfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using options like '--htmlpath' or '--htmlfile' which are not recognized by pytest-html.
3fill in blank
hard

Fix the error in the pytest command to include extra metadata in the HTML report.

PyTest
pytest --html=report.html --[1]='Project: Demo'
Drag options to blanks, or click blank then click option'
Ametadata
Bextra
Cmetadata-add
Dself-contained-html
Attempts:
3 left
💡 Hint
Common Mistakes
Using '--extra' or '--metadata-add' which are not valid pytest-html options.
4fill in blank
hard

Fill both blanks to add a hook function that modifies the HTML report title and environment info.

PyTest
def pytest_html_report_title(report):
    report.title = [1]

def pytest_html_environment(config):
    return [2]
Drag options to blanks, or click blank then click option'
A"My Test Report"
B{"Python": "3.12", "Platform": "Linux"}
C"Test Report"
D{"OS": "Windows", "Browser": "Chrome"}
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect data types like passing a dictionary as title or string as environment info.
5fill in blank
hard

Fill all three blanks to add a pytest hook that appends extra info to the HTML report.

PyTest
def pytest_html_results_table_row(report, cells):
    if report.failed:
        cells.append([1])

@pytest.hookimpl(optionalhook=True)
def pytest_html_results_table_header(cells):
    cells.append([2])

@pytest.hookimpl(optionalhook=True)
def pytest_html_results_table_html(report, data):
    if report.failed:
        data.append([3])
Drag options to blanks, or click blank then click option'
Ahtml.th('Extra Info')
Bhtml.td('Extra Info')
Chtml.div('Failure details')
Dhtml.td('Failure details')
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up td and th tags or using incorrect HTML elements.