Use session.config.hook instead of ihook. Fixes #2124
This commit is contained in:
parent
da40bcf97f
commit
522d59e844
|
@ -754,8 +754,8 @@ class FixtureDef:
|
||||||
func = self._finalizer.pop()
|
func = self._finalizer.pop()
|
||||||
func()
|
func()
|
||||||
finally:
|
finally:
|
||||||
ihook = self._fixturemanager.session.ihook
|
hook = self._fixturemanager.session.config.hook
|
||||||
ihook.pytest_fixture_post_finalizer(fixturedef=self)
|
hook.pytest_fixture_post_finalizer(fixturedef=self)
|
||||||
# even if finalization fails, we invalidate
|
# even if finalization fails, we invalidate
|
||||||
# the cached fixture value
|
# the cached fixture value
|
||||||
if hasattr(self, "cached_result"):
|
if hasattr(self, "cached_result"):
|
||||||
|
@ -783,8 +783,8 @@ class FixtureDef:
|
||||||
self.finish()
|
self.finish()
|
||||||
assert not hasattr(self, "cached_result")
|
assert not hasattr(self, "cached_result")
|
||||||
|
|
||||||
ihook = self._fixturemanager.session.ihook
|
hook = self._fixturemanager.session.config.hook
|
||||||
return ihook.pytest_fixture_setup(fixturedef=self, request=request)
|
return hook.pytest_fixture_setup(fixturedef=self, request=request)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return ("<FixtureDef name=%r scope=%r baseid=%r >" %
|
return ("<FixtureDef name=%r scope=%r baseid=%r >" %
|
||||||
|
|
|
@ -2984,4 +2984,49 @@ class TestParameterizedSubRequest:
|
||||||
""".format(fixfile.strpath, testfile.basename))
|
""".format(fixfile.strpath, testfile.basename))
|
||||||
|
|
||||||
|
|
||||||
|
def test_pytest_fixture_setup_hook(testdir):
|
||||||
|
testdir.makeconftest("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def pytest_fixture_setup():
|
||||||
|
print('pytest_fixture_setup hook called')
|
||||||
|
""")
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def some():
|
||||||
|
return 'some'
|
||||||
|
|
||||||
|
def test_func(some):
|
||||||
|
assert some == 'some'
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("-s")
|
||||||
|
assert result.ret == 0
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*pytest_fixture_setup hook called*",
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
def test_pytest_fixture_post_finalizer_hook(testdir):
|
||||||
|
testdir.makeconftest("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
def pytest_fixture_post_finalizer():
|
||||||
|
print('pytest_fixture_post_finalizer hook called')
|
||||||
|
""")
|
||||||
|
testdir.makepyfile("""
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def some():
|
||||||
|
return 'some'
|
||||||
|
|
||||||
|
def test_func(some):
|
||||||
|
assert some == 'some'
|
||||||
|
""")
|
||||||
|
result = testdir.runpytest("-s")
|
||||||
|
assert result.ret == 0
|
||||||
|
result.stdout.fnmatch_lines([
|
||||||
|
"*pytest_fixture_post_finalizer hook called*",
|
||||||
|
])
|
||||||
|
|
Loading…
Reference in New Issue