Fix issue where fixtures would lose the decorated functionality#3780
Fix issue where fixtures would lose the decorated functionality#3780nicoddemus merged 2 commits intopytest-dev:masterfrom
Conversation
RonnyPfannschmidt
left a comment
There was a problem hiding this comment.
based on the still pending order based incorrectness we should after merging this plan for a rather soonish breaking release where we make fixture definitions truly un-callable
|
I don't know how we can make fixtures definitions un-callable, because we will hit the exact same problem we have today with issuing the warning: we still need to wrap the function to raise an error instead of a warning, which will bring the same class of problems. 😕 |
|
@nicoddemus by returning a non-callable object and by raising hard errors if a fixture definition is wrapped with anything else |
Not sure I follow, won't that bring the exact same problems that we are facing now? I mean, if @classmethod
@pytest.fixture
def setup(cls): ... Because |
|
@nicoddemus as far as i can tell its a unreasonable amount of work to "correctly combine the wrappers before and after a fuxture definition markers, with a gernally tremendous chance to be incorrect |
|
Hi @RonnyPfannschmidt sorry for the delay on this.
I agree it seems hard to implement.
But how would that work for class-scoped fixtures? They by definition need to be import pytest
class Test:
#@classmethod
@pytest.fixture(scope='class', autouse=True)
def setup(self):
self.x = []
def test1(self):
assert self.x == []
self.x.append(1)
def test2(self):
assert self.x == [1]
self.x.append(2)
def test3(self):
assert self.x == [1, 2]Without |
|
Unless you mean that we should apply the |
|
applying class-method should be done in the correct order - aka import pytest
class Test:
@pytest.fixture(scope='class', autouse=True)
@classmethod
def setup(cls):
cls.x = []
def test1(self):
assert self.x == []
self.x.append(1)
def test2(self):
assert self.x == [1]
self.x.append(2)
def test3(self):
assert self.x == [1, 2]we should take a look at warning if |
Oh I see. We should then advertise this more as the correct way to do the decoration. Also I wonder if we might conflict with some other library which also has special requirements? But then again, decorators around fixtures are somewhat rare, and few libraries will return a non-callable object, so I might be overthinking here. 😛
Sounds fair, but do you see a possible problem with us applying it ourselves? I'm not suggesting we do, I think the warning or even an error is a good solution, just curious if you are already foreseeing problems with pytest applying the |
|
@nicoddemus its already tricky as is - it would be even worse with multi scoped-fixtures should they ever land - in addition class scope is possibly declared outside - so from my pov there is a massive amount of special cases for next to no gain - warning people to make this right is a lot more easy than correctly setting up things |
Oh yeah!
Sure sounds reasonable. Thanks for the patience to discuss all the points. 👍 Should we merge this then? It seems like it is an improvement regardless. |
testing/test_compat.py
Outdated
| return "<Evil left={left}>".format(left=self.left) | ||
|
|
||
| def __getattr__(self, attr): | ||
| if attr == "__pytest_wrapped__": |
There was a problem hiding this comment.
i just noticed this special case - we shouldn't have it - because in practice this means we blow up on evil objects there
There was a problem hiding this comment.
Good catch. Used a custom holder class so we can be sure we are unwrapping an object set by us.
3bc90b8 to
67106f0
Compare
Fix #3774