Created
December 16, 2018 01:50
-
-
Save zkan/5f2721bd25a472cd6825f2ba65a98d8a to your computer and use it in GitHub Desktop.
FizzBuzz test using Pytest with fixtures and test parametrization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
class FizzBuzz: | |
def say(self, number): | |
if number % 3 == 0 and number % 5 == 0: | |
return 'FizzBuzz' | |
elif number % 3 == 0: | |
return 'Fizz' | |
elif number % 5 == 0: | |
return 'Buzz' | |
else: | |
return number | |
@pytest.fixture | |
def fizzbuzz(): | |
f = FizzBuzz() | |
return f | |
@pytest.mark.parametrize('test_input, expected', [ | |
(3, 'Fizz'), | |
(6, 'Fizz'), | |
(5, 'Buzz'), | |
(10, 'Buzz'), | |
(15, 'FizzBuzz'), | |
(30, 'FizzBuzz'), | |
(2, 2), | |
(7, 7), | |
]) | |
def test_fizzbuzz(fizzbuzz, test_input, expected): | |
assert fizzbuzz.say(test_input) == expected |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment