Skip to content

Commit

Permalink
Use session.config.hook instead of ihook. Fixes #2124
Browse files Browse the repository at this point in the history
  • Loading branch information
malinoff committed Dec 10, 2016
1 parent da40bcf commit 522d59e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
8 changes: 4 additions & 4 deletions _pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,8 @@ def finish(self):
func = self._finalizer.pop()
func()
finally:
ihook = self._fixturemanager.session.ihook
ihook.pytest_fixture_post_finalizer(fixturedef=self)
hook = self._fixturemanager.session.config.hook
hook.pytest_fixture_post_finalizer(fixturedef=self)
# even if finalization fails, we invalidate
# the cached fixture value
if hasattr(self, "cached_result"):
Expand Down Expand Up @@ -783,8 +783,8 @@ def execute(self, request):
self.finish()
assert not hasattr(self, "cached_result")

ihook = self._fixturemanager.session.ihook
return ihook.pytest_fixture_setup(fixturedef=self, request=request)
hook = self._fixturemanager.session.config.hook
return hook.pytest_fixture_setup(fixturedef=self, request=request)

def __repr__(self):
return ("<FixtureDef name=%r scope=%r baseid=%r >" %
Expand Down
45 changes: 45 additions & 0 deletions testing/python/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -2984,4 +2984,49 @@ def test_foo(request):
""".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*",
])

0 comments on commit 522d59e

Please sign in to comment.