Вот упрощенный пример моего кода:
Код: Выделить всё
# example.py
def outer_function(a, b):
"""
Example outer function that performs some operations.
"""
def inner_function(x, y):
"""
Nested function that I want to test.
"""
return x + y
# Some operations using inner_function
result = inner_function(a, b)
return result
- Сложение двух положительных чисел
- Сложение положительных и отрицательных чисел
- Сложение двух отрицательных чисел
< li>Добавление нуля к числу
Пример тестовой функции:
Код: Выделить всё
# test_example.py
import pytest
@pytest.mark.parametrize("x, y, expected", [
(1, 2, 3), # Adding two positive numbers
(1, -1, 0), # Adding positive and negative numbers
(-1, -2, -3), # Adding two negative numbers
(0, 5, 5), # Adding zero to a number
(3, 0, 3) # Adding a number to zero
])
def test_inner_function(x, y, expected):
"""
Describe how to test the inner_function here.
"""
# Code to test inner_function goes here.
Подробнее здесь: https://stackoverflow.com/questions/788 ... outer-func