Skip to content

Instantly share code, notes, and snippets.

@Cjkjvfnby
Created April 3, 2021 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cjkjvfnby/58e43755f186de0b2c6176c3750975aa to your computer and use it in GitHub Desktop.
Save Cjkjvfnby/58e43755f186de0b2c6176c3750975aa to your computer and use it in GitHub Desktop.
Testing different implementations with pytest. To add/remove implementation for testing you need just change one line of code.
test_impls.py::test_integer_rounded_to_itself[do_round] PASSED [ 16%]
test_impls.py::test_integer_rounded_to_itself[cut] PASSED [ 33%]
test_impls.py::test_quarter_rounded_down[do_round] PASSED [ 50%]
test_impls.py::test_quarter_rounded_down[cut] PASSED [ 66%]
test_impls.py::test_three_fore_rounded_up[do_round] PASSED [ 83%]
test_impls.py::test_three_fore_rounded_up[cut] FAILED
import pytest
def do_round(x: float) -> int:
return int(round(x, 0))
def cut(x: float) -> int:
return int(x)
functions_under_test = [do_round, cut]
@pytest.fixture(
params=functions_under_test, ids=[x.__name__ for x in functions_under_test]
)
def function(request):
return request.param
def test_integer_rounded_to_itself(function):
assert function(1.0) == 1
def test_quarter_rounded_down(function):
assert function(0.25) == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment