Last active
December 16, 2018 01:49
-
-
Save zkan/4cc9fecc8c5a829a356f81561f0aa251 to your computer and use it in GitHub Desktop.
FizzBuzz test using Pytest with fixtures
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 | |
def test_input_is_divisible_by_3_should_get_fizz(fizzbuzz): | |
assert fizzbuzz.say(3) == 'Fizz' | |
assert fizzbuzz.say(6) == 'Fizz' | |
def test_input_is_divisible_by_5_should_get_buzz(fizzbuzz): | |
assert fizzbuzz.say(5) == 'Buzz' | |
assert fizzbuzz.say(10) == 'Buzz' | |
def test_input_is_divisible_by_3_and_5_should_get_fizzbuzz(fizzbuzz): | |
assert fizzbuzz.say(15) == 'FizzBuzz' | |
assert fizzbuzz.say(30) == 'FizzBuzz' | |
def test_input_is_number_should_get_number(fizzbuzz): | |
assert fizzbuzz.say(2) == 2 | |
assert fizzbuzz.say(7) == 7 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment