How to create Abstract Test aka Contract Test using pytest fixtures Posted on 2015-09-20 in dev The solution I came up with: import pytest def square(num): return num * num def recursive_map(f, _list): """Recusive map implementation.""" if not _list: return [] else: head, *tail = _list h = [f(head)] h.extend(recursive_map(f, tail)) return h class MapContract(object): @pytest.fixture def a_map(self): raise NotImplementedError('Not Implemented Yet') def test_can_handle_small_list(self, a_map): assert list(a_map(square, [1,3,4])) == [1, 9, 16] def test_can_handle_large_list(self, a_map): num = 10000 assert len(list(a_map(square, range(num)))) == num class TestSTDLibContract(MapContract): @pytest.fixture def a_map(self): return map class TestRecursiveMap(MapContract): @pytest.fixture def a_map(self): return recursive_map Further reading: Abstract Test Case Contract Test pytest fixtures Python pytest test