Testing with pytest - up1/course-python-workshop GitHub Wiki

Testing with pytest

Install pytest

$pip install pytest

File hello.py

def say_hi(name: str) -> str:
    """
    Print a greeting message with the provided name.
    
    Args:
        name (str): The name to greet.
    """
    return f"Hi, {name}!"

File hello_test.py

from hello import say_hi

def test_say_hi():
    assert say_hi("Alice") == "Hi, Alice!"
    assert say_hi("Bob") == "Hi, Bob!"
    assert say_hi("Charlie") == "Hi, Charlie!"
    assert say_hi("") == "Hi, !"
    assert say_hi(None) == "Hi, None!"

Run

$pytest

$pytest hello_test.py