Junior — Middle
Have you used decorators in tests with PyTest to organize test cases?
sobes.tech AI
Answer from AI
Yes, in PyTest, you can use decorators to organize tests and parameterize them. For example, with @pytest.mark.parametrize, you can run a single test with different input data:
import pytest
@pytest.mark.parametrize("input,expected", [
(2, 4),
(3, 9),
(4, 16),
])
def test_square(input, expected):
assert input ** 2 == expected
This allows you to describe many similar test cases compactly without duplicating code.