Если вы хотите протестировать свою функцию на разных примерах, используйте декоратор pytest.mark.parametrize из библиотеки pytest.
В приведенном выше коде ожидается, что первое предложение будет содержать слово "duck", а второе предложение не будет содержать этого слова. При запуске pytest прошло 2 теста.
import pytest
def text_contain_word(word: str, text: str):
'''Find whether the text contains a particular word'''
return word in text
test = [
('There is a duck in this text',True),
('There is nothing here', False)
]
@pytest.mark.parametrize('sample, expected', test)
def test_text_contain_word(sample, expected):
word = 'duck'
assert text_contain_word(word, sample) == expected▪Github
▪Python Testing с pytest
@data_analysis_ml
