Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

funcarg/fixture uses a different reference to object #203

Closed
pytestbot opened this issue Oct 19, 2012 · 5 comments
Closed

funcarg/fixture uses a different reference to object #203

pytestbot opened this issue Oct 19, 2012 · 5 comments
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: eduardo schettino (BitBucket: schettino72, GitHub: schettino72)


Something like this (using old funcargs) used to work on 2.2
but now fails on 2.3.

#!python
import pytest

class TestClass:
    @pytest.fixture()
    def my_setup(self, request):
        self.foo = True

    def test_method1(self, my_setup):
       assert self.foo

The object instance used to run the test is different from
the instance used to calculate the value of the fixture.
So modification to "self" in the fixture are lost.


@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


seems to be a regression, indeed. Not sure why there wasn't a test for this already.

Meanwhile you can use "request.instance.foo = True".

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


fix issue203 - fixture functions with a scope=function should have a "self" that points to the actual instance with which the test functions run.

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


you can install the new version with "pip install -i http://pypi.testrun.org -U pytest" which should give you at least "dev2". Would be good if you confirm it works for you. Willthen do another release on monday or so. Let the bug reports flow :)

@pytestbot
Copy link
Contributor Author

Original comment by eduardo schettino (BitBucket: schettino72, GitHub: schettino72):


works for me. thanks for the quickly reply.

sorry for testing after the release... I planned to try py.test2.3 on the weekend but you were faster than me :D I converted some tests to 2.3 style and i like the result. cheers

@pytestbot
Copy link
Contributor Author

Original comment by holger krekel (BitBucket: hpk42, GitHub: hpk42):


thanks for confirmation and feedback! I did a pytest-2.3.1 release - i'd like others to spare the experience/bug :)

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Jun 15, 2015
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
There is no need to keep the pickled grammar files in git. PR pytest-dev#203 will
move them into a user-specific cache directory any way.

See: psf/black#192
Signed-off-by: Christian Heimes <[email protected]>
fkohlgrueber pushed a commit to fkohlgrueber/pytest that referenced this issue Oct 27, 2018
mgorny pushed a commit to mgorny/pytest that referenced this issue May 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

1 participant