Fix fixture parameter display when ids is a function
This commit is contained in:
parent
1a5e530b98
commit
c6af737d4e
|
@ -2480,7 +2480,7 @@ class FixtureDef:
|
||||||
if hasattr(self, "cached_result"):
|
if hasattr(self, "cached_result"):
|
||||||
config = self._fixturemanager.config
|
config = self._fixturemanager.config
|
||||||
if config.option.setuponly or config.option.setupplan:
|
if config.option.setuponly or config.option.setupplan:
|
||||||
self._log_fixture_stack('TEARDOWN')
|
self._show_fixture_action('TEARDOWN')
|
||||||
if hasattr(self, "cached_param"):
|
if hasattr(self, "cached_param"):
|
||||||
del self.cached_param
|
del self.cached_param
|
||||||
del self.cached_result
|
del self.cached_result
|
||||||
|
@ -2533,22 +2533,24 @@ class FixtureDef:
|
||||||
else:
|
else:
|
||||||
result = call_fixture_func(fixturefunc, request, kwargs)
|
result = call_fixture_func(fixturefunc, request, kwargs)
|
||||||
if config.option.setuponly or config.option.setupplan:
|
if config.option.setuponly or config.option.setupplan:
|
||||||
# We want to access the params of ids if they exist also in during
|
|
||||||
# the finish() method.
|
|
||||||
if hasattr(request, 'param'):
|
if hasattr(request, 'param'):
|
||||||
|
# Save the fixture parameter so ._show_fixture_action() can
|
||||||
|
# display it now and during the teardown (in .finish()).
|
||||||
if self.ids:
|
if self.ids:
|
||||||
ind = self.params.index(request.param)
|
if callable(self.ids):
|
||||||
self.cached_param = self.ids[ind]
|
self.cached_param = self.ids(request.param)
|
||||||
|
else:
|
||||||
|
self.cached_param = self.ids[request.param_index]
|
||||||
else:
|
else:
|
||||||
self.cached_param = request.param
|
self.cached_param = request.param
|
||||||
self._log_fixture_stack('SETUP')
|
self._show_fixture_action('SETUP')
|
||||||
except Exception:
|
except Exception:
|
||||||
self.cached_result = (None, my_cache_key, sys.exc_info())
|
self.cached_result = (None, my_cache_key, sys.exc_info())
|
||||||
raise
|
raise
|
||||||
self.cached_result = (result, my_cache_key, None)
|
self.cached_result = (result, my_cache_key, None)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _log_fixture_stack(self, what):
|
def _show_fixture_action(self, what):
|
||||||
config = self._fixturemanager.config
|
config = self._fixturemanager.config
|
||||||
capman = config.pluginmanager.getplugin('capturemanager')
|
capman = config.pluginmanager.getplugin('capturemanager')
|
||||||
if capman:
|
if capman:
|
||||||
|
|
|
@ -159,6 +159,25 @@ def test_show_fixtures_with_parameter_ids(testdir, mode):
|
||||||
])
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def test_show_fixtures_with_parameter_ids_function(testdir, mode):
|
||||||
|
p = testdir.makepyfile('''
|
||||||
|
import pytest
|
||||||
|
@pytest.fixture(params=['foo', 'bar'], ids=lambda p: p.upper())
|
||||||
|
def foobar():
|
||||||
|
pass
|
||||||
|
def test_foobar(foobar):
|
||||||
|
pass
|
||||||
|
''')
|
||||||
|
|
||||||
|
result = testdir.runpytest(mode, p)
|
||||||
|
assert result.ret == 0
|
||||||
|
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
'*SETUP F foobar?FOO?',
|
||||||
|
'*SETUP F foobar?BAR?',
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
def test_dynamic_fixture_request(testdir):
|
def test_dynamic_fixture_request(testdir):
|
||||||
p = testdir.makepyfile('''
|
p = testdir.makepyfile('''
|
||||||
import pytest
|
import pytest
|
||||||
|
|
Loading…
Reference in New Issue