[Pytest-commit] Issue #674: Fixtures from methods wrongly get rebound to request.instance (hpk42/pytest)

Ionel Maries Cristian issues-reply at bitbucket.org
Fri Feb 6 14:24:39 CET 2015


New issue 674: Fixtures from methods wrongly get rebound to request.instance
https://bitbucket.org/hpk42/pytest/issue/674/fixtures-from-methods-wrongly-get-rebound

Ionel Maries Cristian:

In `python.py` there's code like this
```
       if self.unittest:
            result = self.func(request.instance, **kwargs)
        else:
            fixturefunc = self.func
            # the fixture function needs to be bound to the actual
            # request.instance so that code working with "self" behaves
            # as expected.
            if request.instance is not None:
                fixturefunc = getimfunc(self.func)
                if fixturefunc != self.func:
                    fixturefunc = fixturefunc.__get__(request.instance)
            try:
                result = call_fixture_func(fixturefunc, request, kwargs,
                                           self.yieldctx)
            except Exception:
                self.cached_result = (None, my_cache_key, sys.exc_info())
                raise
        self.cached_result = (result, my_cache_key, None)
```

If you create a fixture from a plugin like this: https://github.com/ionelmc/pytest-benchmark/blob/9f2c62affb62d580f115d72f99cb662306bfa1d2/src/pytest_benchmark/plugin.py#L294
then you're going to have the request.instance as self.




More information about the pytest-commit mailing list