Skip to content

Question: writing a plugin with a fixture that can access its plugin instance properties #2270

@westhomas

Description

@westhomas

Sample code:

class CollectorPlugin:
    def __init__(self, group_name):
        self.group_name = group_name
        self.collected = []

    @pytest.fixture
    def capture_logs(self, request):
        
        #self is an instance of test_method1 NOT of CollectorPlugin?
        print(self.group_name)


collector_plugin = CollectorPlugin("test")

returncode = pytest.main(
    args,
    plugins=[collector_plugin]
)

def test_method1(capture_logs):
    assert True

The capture_logs fixture can't seem to access the plugin's instance object self.

How can I pass some data to the fixture from the plugin?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: bugproblem that needs to be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions