0
0
PyTesttesting~10 mins

PyTest vs unittest vs nose comparison - Test Execution Compared

Choose your learning style9 modes available
Test Overview

This test checks a simple function using PyTest framework. It verifies that the function returns the expected result. This helps compare how PyTest runs tests versus unittest and nose.

Test Code - PyTest
PyTest
import pytest

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

def test_add():
    assert add(2, 3) == 5
Execution Trace - 5 Steps
StepActionSystem StateAssertionResult
1Test startsPyTest test runner initializes-PASS
2PyTest collects test functions starting with 'test_'Test function 'test_add' found-PASS
3PyTest runs test_add functionFunction add(2, 3) is calledCheck if add(2, 3) == 5PASS
4Assertion passes as 2 + 3 equals 5Test completes successfullyassert add(2, 3) == 5PASS
5Test ends and report shows 1 test passedTest summary displayed-PASS
Failure Scenario
Failing Condition: The add function returns wrong result, e.g., add(2, 3) returns 6
Execution Trace Quiz - 3 Questions
Test your understanding
What does PyTest look for to find test functions?
AFunctions ending with '_test'
BFunctions starting with 'check_'
CFunctions starting with 'test_'
DFunctions with @test decorator
Key Result
PyTest is simple and flexible, allowing tests as plain functions with assert statements, unlike unittest which requires classes and methods. Nose is similar to PyTest but less maintained now.