-
-
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.
This file contains 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
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 |
This file contains 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 | |
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