Challenge - 5 Problems
pytest-html Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2: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:
What will be the result?
pytest --html=report.html --self-contained-html
What will be the result?
Attempts:
2 left
💡 Hint
Think about what --self-contained-html means for the report file.
✗ Incorrect
The --html option creates an HTML report file. The --self-contained-html option embeds all CSS and JS inside the HTML file, making it standalone and portable.
❓ assertion
intermediate2: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?
Which assertion is correct?
PyTest
import os def test_report_exists(): # Assume pytest run already happened # Which assertion below is correct? pass
Attempts:
2 left
💡 Hint
Check if the file exists and is a file, not a directory.
✗ Incorrect
os.path.isfile returns True if the path exists and is a file. This is the correct way to assert the report file was created.
🔧 Debug
advanced2: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?
However, the screenshots do not appear in the HTML report.
What is the most likely reason?
Attempts:
2 left
💡 Hint
Think about how pytest-html expects extra content to be added.
✗ Incorrect
pytest-html requires screenshots to be attached using the pytest_html.extras.image() function passed as an extra argument to the report. Simply saving screenshots is not enough.
❓ framework
advanced2: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?
Which method correctly achieves this?
Attempts:
2 left
💡 Hint
Look for a pytest hook specifically for report title customization.
✗ Incorrect
pytest-html supports customizing the report title by implementing the pytest_html_report_title hook in conftest.py, where you set report.title to the desired string.
🧠 Conceptual
expert2: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?
Which statement best describes its main advantage?
Attempts:
2 left
💡 Hint
Think about what 'self-contained' means for a file.
✗ Incorrect
The --self-contained-html option embeds all required CSS and JS inside the HTML file, so the report can be opened anywhere without needing extra files.