Replies: 6 comments 1 reply
-
At first glance it looks like misuse of mocking, nothing pytest can do here |
Beta Was this translation helpful? Give feedback.
-
Why is that a misuse? Any idea how I can achieve my goal in "legal" ways? |
Beta Was this translation helpful? Give feedback.
-
BTW, it works if I change the class definition to this: class A(object):
def __new__(cls, *_, **__):
return super(A, cls).__new__(cls)
def __init__(self, x):
self.x = x |
Beta Was this translation helpful? Give feedback.
-
To figure the correct way I'd have to experiment, i would suggest to Patch |
Beta Was this translation helpful? Give feedback.
-
Weird, I can't reproduce the problem either on I would try @RonnyPfannschmidt's suggestion though. |
Beta Was this translation helpful? Give feedback.
-
@ymyke ~4 years later...
Also, see the implementations of I suspect that once the |
Beta Was this translation helpful? Give feedback.
-
Potential pytest bug (see also Comments section).
Problem description
My goal is to patch a class'
__new__
method in order to control the exact object it creates in a test case. See the code below.Each of the two tests
test_1
andtest_2
work as expected when run individually. When they are both run consecutively, however,test_2
fails with:TypeError: object.__new__() takes exactly one argument (the type to instantiate)
Code
Comments
I'm not sure if this is really a pytest issue, since the problem also occurs even if I store away the original
__new__
method pointer and restore it at the end oftest_1
. Either way, I'd appreciate any help in finding out what is going on.Environment
Beta Was this translation helpful? Give feedback.
All reactions