def mygen(name): """An infinite generator of ids""" for i in itt.count(): yield "%s{%i}" % (name, i) if LooseVersion(pytest.__version__) < LooseVersion('3.0.0'): @fixture @parametrize("x", [1, 2], ids=mygen("x")) def my_fixture(x): return x a = param_fixtures("a", ['aa', 'ab'], ids=mygen("a")) my_union = fixture_union("my_union", [a], ids=mygen("myunion")) def test_foo(my_fixture, my_union, a): pass def test_synthesis(module_results_dct): assert list(module_results_dct) == [ 'test_foo[x{0}-myunion{0}-a{0}]', 'test_foo[x{0}-myunion{0}-a{1}]', 'test_foo[x{1}-myunion{0}-a{0}]', 'test_foo[x{1}-myunion{0}-a{1}]' ] else: @fixture
print(fixture_fun) f_list.append(fixture_fun.__name__) return fixture_fun @fixture(hook=my_hook) def foo(): return 2, 1 o, p = unpack_fixture('o,p', foo, hook=my_hook) p1 = param_fixture("p1", [1, 2], hook=my_hook) p2, p3 = param_fixtures("p2,p3", [(3, 4)], hook=my_hook) u = fixture_union("u", (o, p), hook=my_hook) @parametrize("arg", [fixture_ref(u), fixture_ref(p1)]) def test_a(arg, p2, p3): pass def test_synthesis(module_results_dct): assert list(module_results_dct) == [ 'test_a[u-/o-3-4]', 'test_a[u-/p-3-4]', 'test_a[p1-1-3-4]',
my_parameter2 = param_fixture("my_parameter2", [3, 4]) # Returning value @pytest.fixture def fixture_uses_param(my_parameter, my_parameter2): return my_parameter, my_parameter2 def test_uses_param(my_parameter, my_parameter2, fixture_uses_param): # check that the parameter injected in both is the same assert my_parameter, my_parameter2 == fixture_uses_param # ---------- (2) # create a 2-tuple parameter fixture without symbol creation param_fixtures("arg1, arg2", [(1, 2), (3, 4)]) # Testing param_fixtures with single arg arg3 = param_fixture("arg3", [5, 6]) @pytest.fixture def fixture_uses_param2(arg2): return arg2 def test_uses_param2(arg1, arg2, arg3, fixture_uses_param2): # check that the parameter injected in both is the same assert arg2 == fixture_uses_param2 assert arg1, arg2 in [(1, 2), (3, 4)] assert arg3 in [5, 6]