Skip to content

Commit

Permalink
Improve CHANGELOG and add some comments
Browse files Browse the repository at this point in the history
Ref: #5768
  • Loading branch information
nicoddemus committed Aug 30, 2019
1 parent 6238112 commit 3ddbc7f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion changelog/2270.bugfix.rst
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Fix ``self`` reference in function scoped fixtures that are in a plugin class
Fixed ``self`` reference in function-scoped fixtures defined plugin classes: previously ``self``
would be a reference to a *test* class, not the *plugin* class.
2 changes: 2 additions & 0 deletions src/_pytest/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,8 @@ def resolve_fixture_function(fixturedef, request):
# request.instance so that code working with "fixturedef" behaves
# as expected.
if request.instance is not None:
# handle the case where fixture is defined not in a test class, but some other class
# (for example a plugin class with a fixture), see #2270
if hasattr(fixturefunc, "__self__") and not isinstance(
request.instance, fixturefunc.__self__.__class__
):
Expand Down
3 changes: 3 additions & 0 deletions testing/python/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -3946,6 +3946,9 @@ def test_2(fix):
reprec.assertoutcome(passed=2)

def test_class_fixture_self_instance(self, testdir):
"""Check that plugin classes which implement fixtures receive the plugin instance
as self (see #2270).
"""
testdir.makeconftest(
"""
import pytest
Expand Down

0 comments on commit 3ddbc7f

Please sign in to comment.