Skip to content

Instantly share code, notes, and snippets.

@geryxyz
Created February 28, 2022 19:07
Show Gist options
  • Save geryxyz/6e9b23ce4fbb22f1b86f066004c2a612 to your computer and use it in GitHub Desktop.
Save geryxyz/6e9b23ce4fbb22f1b86f066004c2a612 to your computer and use it in GitHub Desktop.
Decouple test cases from system under test
import pytest
class ClassA(object):
def apply(self, *args):
return 42
class ClassB(object):
def apply(self, *args):
return 0
def func_gamma(something):
...
def func_delta():
...
@pytest.mark.parametrize(argnames='correct_class', argvalues=[ClassA, ClassB])
def test_decoupled_from_class(correct_class):
# arrange
params = "hello"
# act
object_under_test = correct_class()
actual = object_under_test.apply(params)
# assert
expected = 42
assert actual == expected
@pytest.mark.parametrize(argnames='function_under_test', argvalues=[func_delta, func_gamma])
def test_decoupled_from_function(function_under_test):
# arrange
params = "hello"
# act
actual = function_under_test(params)
# assert
expected = 42
assert actual == expected
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment