pytest_book/src/chapter-14/create_tests_via_parametriz.../test_parametrize.py

33 lines
756 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import pytest
# 这是一个英国游戏逢3就fizz,逢5就buzz如果是35的倍数则fizzbuzz
# 类似中国的逢3或3的倍数就敲一下桌子其他就说出来124578101114
RULES = (
(3 * 5, "FizzBuzz"),
(3, "Fizz"),
(5, "Buzz"),
)
def fizzbuzz(number):
for div_number, substitution in RULES:
if not number % div_number:
return substitution
return str(number)
@pytest.mark.parametrize(
'number, word', [
(1, '1'),
(3, 'Fizz'),
(5, 'Buzz'),
(10, 'Buzz'),
(15, 'FizzBuzz'),
(16, '16')
]
)
def test_fizzbuzz(number, word):
assert fizzbuzz(number) == word