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

Mocked new_instances are not properly cleaned by teardown in Python 3 #16

Open
lindycoder opened this issue Oct 17, 2016 · 6 comments
Open

Comments

@lindycoder
Copy link

lindycoder commented Oct 17, 2016

Hello!

It would seem that when using flexmock(<class>).new_instances() in python 3.4 won't clean the bindings on the class upon calling teardown.

This is an example script using latest flexmock==0.10.2 on Python 3.4.4

from flexmock._api import flexmock, flexmock_teardown


class MyClass:
    def __init__(self, param):
        pass

flexmock(MyClass).new_instances(flexmock())
flexmock_teardown()

obj = MyClass("hehe")

print("All good! :D")

Output is

Traceback (most recent call last):
  File "issue.py", line 11, in <module>
    obj = MyClass("hehe")
TypeError: object() takes no parameters

If i try to call MyClass without param error becomes

Traceback (most recent call last):
  File "issue.py", line 11, in <module>
    obj = MyClass()
TypeError: __init__() missing 1 required positional argument: 'param'

It works fine on Python 2.7.11

@bkabrda
Copy link
Collaborator

bkabrda commented Oct 19, 2016

Hi, thanks for the report, I'll look into it. It definitely looks like a bug and I can reproduce it.

@bkabrda
Copy link
Collaborator

bkabrda commented Oct 19, 2016

So I think you're hitting #13, which is caused by a bug in Python itself [1]. The weird thing is, I have Python 3.5.2 where this should already be fixed and I'm still getting the error. So either the fix is wrong or there's another problem somewhere. I'll continue investigating.

[1] http://bugs.python.org/issue25731

@bkabrda
Copy link
Collaborator

bkabrda commented Oct 19, 2016

So yeah, the fix for the underlying Python issue has been reverted. I have a feeling that it was reverted by mistake, but I'm not completely sure. I left a comment at the issue, so we'll see [1].

[1] http://bugs.python.org/issue25731#msg278962

@ollipa ollipa changed the title Mocked new_instances are not properly cleaned by teardown in python 3.4 Mocked new_instances are not properly cleaned by teardown in Python 3 Aug 14, 2021
@ollipa ollipa added the bug label Aug 23, 2021
@wojtha
Copy link

wojtha commented Jan 17, 2022

We just run into this issue in 2022. @bkabrda seems that your voice in the related Python issue in 2016 wasn't heard ☹️ I suggest we should raise a warning when new_instances() is called until the issue is resolved. Or perhaps make a note about it in the documentation.

@ollipa
Copy link
Member

ollipa commented Feb 6, 2022

@wojtha, thank you for your suggestions. I added a warning to the documentation in PR #127. I think before we raise a warning when new_instances method is called, we should first think about some alternative way to fake new instances.

As a side note, this bug seems to only affect CPython. For example, PyPy doesn't suffer from this bug.

@christophe-riolo
Copy link
Contributor

We should probably follow up on the Python bug tracker also, it's tricky to fix this bug without this 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants