0
0
PyTesttesting~20 mins

pytest-html for HTML reports - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
pytest-html Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this pytest-html report generation command?
You run the following command to generate an HTML report after your pytest tests:
pytest --html=report.html --self-contained-html

What will be the result?
ANo report file is created because --self-contained-html is not a valid option.
BAn HTML file named report.html is created but requires external CSS and JS files to display properly.
CAn HTML file named report.html is created with embedded CSS and JavaScript for a standalone report.
DThe command runs tests but outputs results only in the console, no HTML file is generated.
Attempts:
2 left
💡 Hint
Think about what --self-contained-html means for the report file.
assertion
intermediate
2:00remaining
Which assertion correctly verifies the presence of the HTML report file after pytest run?
After running pytest with pytest-html, you want to check in your test script that the report file was created.
Which assertion is correct?
PyTest
import os

def test_report_exists():
    # Assume pytest run already happened
    # Which assertion below is correct?
    pass
Aassert os.path.exists('report.html') == False
Bassert os.path.isfile('report.html')
Cassert os.path.isdir('report.html')
Dassert 'report.html' in os.listdir() == False
Attempts:
2 left
💡 Hint
Check if the file exists and is a file, not a directory.
🔧 Debug
advanced
2:00remaining
Why does the pytest-html report not include screenshots on failure?
You configured pytest-html to generate reports and added code to capture screenshots on test failure.
However, the screenshots do not appear in the HTML report.
What is the most likely reason?
AThe screenshots were saved but not attached to the pytest-html report using the extra argument.
Bpytest-html does not support embedding images in reports.
CScreenshots must be saved as .txt files to appear in the report.
DThe report file was generated before the screenshots were taken.
Attempts:
2 left
💡 Hint
Think about how pytest-html expects extra content to be added.
framework
advanced
2:00remaining
How to customize the pytest-html report title?
You want to change the default title of the pytest-html report to "My Test Report".
Which method correctly achieves this?
AUse pytest --html=report.html and add a pytest_html_report_title hook in conftest.py to set the title.
BAdd a pytest hook in conftest.py to set config._metadata['Title'] = 'My Test Report'
CRename the generated report.html file to My Test Report.html after pytest finishes.
DRun pytest with --html=report.html --self-contained-html --title="My Test Report"
Attempts:
2 left
💡 Hint
Look for a pytest hook specifically for report title customization.
🧠 Conceptual
expert
2:00remaining
What is the main advantage of using --self-contained-html with pytest-html reports?
Consider the following options about the --self-contained-html flag when generating pytest-html reports.
Which statement best describes its main advantage?
AIt enables live updating of the report while tests are running.
BIt compresses the report file to reduce disk space usage significantly.
CIt automatically uploads the report to a remote server for sharing.
DIt embeds all CSS and JavaScript inside the HTML file, making the report portable without external dependencies.
Attempts:
2 left
💡 Hint
Think about what 'self-contained' means for a file.