Skip to content

Commit 3e52b98

Browse files
authored
Merge pull request #47 from YannickJadoul/lazy-fixture-param-ids
Adding pytest_make_parametrize_id implementation to get better default ids for lazy fixtures
2 parents 2079734 + 302775d commit 3e52b98

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

pytest_lazyfixture.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def pytest_pycollect_makeitem(collector, name, obj):
6262
current_node = None
6363

6464

65+
def pytest_make_parametrize_id(config, val, argname):
66+
if is_lazy_fixture(val):
67+
return val.name
68+
69+
6570
@pytest.hookimpl(hookwrapper=True)
6671
def pytest_generate_tests(metafunc):
6772
yield

tests/test_lazyfixture.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,3 +878,29 @@ def test_bug(value):
878878
""")
879879
result = testdir.inline_run('-s')
880880
result.assertoutcome(passed=2)
881+
882+
883+
# https://github.com/TvoroG/pytest-lazy-fixture/issues/46
884+
def test_lazy_fixture_ids(testdir):
885+
testdir.makepyfile("""
886+
import pytest
887+
from pytest_lazyfixture import lazy_fixture
888+
889+
@pytest.fixture()
890+
def foo():
891+
return "foo"
892+
893+
@pytest.fixture(params=['spam', 'eggs'])
894+
def bar(request):
895+
return "bar-{}".format(request.param)
896+
897+
@pytest.mark.parametrize("data", [lazy_fixture("foo"),
898+
lazy_fixture("bar")])
899+
def test_the_thing(data):
900+
assert False
901+
""")
902+
result = testdir.runpytest('--collect-only')
903+
stdout = result.stdout.str()
904+
assert 'test_the_thing[foo]' in stdout
905+
assert 'test_the_thing[bar-spam]' in stdout
906+
assert 'test_the_thing[bar-eggs]' in stdout

0 commit comments

Comments
 (0)