Skip to content

Instantly share code, notes, and snippets.

@zkan
Created December 16, 2018 01:50
Show Gist options
  • Save zkan/5f2721bd25a472cd6825f2ba65a98d8a to your computer and use it in GitHub Desktop.
Save zkan/5f2721bd25a472cd6825f2ba65a98d8a to your computer and use it in GitHub Desktop.
FizzBuzz test using Pytest with fixtures and test parametrization
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