Skip to content

Commit 3ddbc7f

Browse files
committed
Improve CHANGELOG and add some comments
Ref: #5768
1 parent 6238112 commit 3ddbc7f

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

changelog/2270.bugfix.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
Fix ``self`` reference in function scoped fixtures that are in a plugin class
1+
Fixed ``self`` reference in function-scoped fixtures defined plugin classes: previously ``self``
2+
would be a reference to a *test* class, not the *plugin* class.

src/_pytest/fixtures.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,8 @@ def resolve_fixture_function(fixturedef, request):
897897
# request.instance so that code working with "fixturedef" behaves
898898
# as expected.
899899
if request.instance is not None:
900+
# handle the case where fixture is defined not in a test class, but some other class
901+
# (for example a plugin class with a fixture), see #2270
900902
if hasattr(fixturefunc, "__self__") and not isinstance(
901903
request.instance, fixturefunc.__self__.__class__
902904
):

testing/python/fixtures.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,6 +3946,9 @@ def test_2(fix):
39463946
reprec.assertoutcome(passed=2)
39473947

39483948
def test_class_fixture_self_instance(self, testdir):
3949+
"""Check that plugin classes which implement fixtures receive the plugin instance
3950+
as self (see #2270).
3951+
"""
39493952
testdir.makeconftest(
39503953
"""
39513954
import pytest

0 commit comments

Comments
 (0)