0
0
PyTesttesting~10 mins

pytest-html for HTML reports - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test runs a simple function check and generates an HTML report using pytest-html plugin. It verifies that the test passes and the report is created.

Test Code - pytest
PyTest
import pytest

def add(a, b):
    return a + b

def test_add():
    assert add(2, 3) == 5

# To run this test and generate HTML report, use:
# pytest --html=report.html --self-contained-html
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test runner starts pytest with HTML report optionTerminal ready to run pytest command-PASS
2Pytest discovers test_add functionTest function test_add found in test file-PASS
3Pytest executes test_addRunning test_add which calls add(2, 3)Check if add(2, 3) == 5PASS
4Test passes as assertion is trueTest completed successfullyassert 5 == 5PASS
5pytest-html plugin generates report.html fileHTML report file created with test results summaryReport file exists and contains test summaryPASS
Failure Scenario
Failing Condition: Assertion in test_add fails (e.g., add(2, 3) != 5)
Execution Trace Quiz - 3 Questions
Test your understanding
What does the pytest-html plugin do in this test?
AGenerates an HTML report file with test results
BRuns the test functions automatically
CFixes failing tests
DAdds new test cases
Key Result
Using pytest-html helps create easy-to-read HTML reports that summarize test results, making it simple to share and review test outcomes.