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

Copying a mock object breaks coverage utility #48

Closed
GoogleCodeExporter opened this issue Apr 28, 2016 · 5 comments
Closed

Copying a mock object breaks coverage utility #48

GoogleCodeExporter opened this issue Apr 28, 2016 · 5 comments

Comments

@GoogleCodeExporter
Copy link

Copying an instance of a Mock object with the copy module breaks the function 
of coverage for subsequent lines of code.

Win32 Python 2.5.4

Latest mock (0.7something)

Latest coverage snapshot but old versions of it do it too, like the ancient 
version that comes with eclipse pydev.

I opened a ticket in coverage as well: 
http://bitbucket.org/ned/coveragepy/issue/93/copying-a-mock-object-breaks-covera
ge#comment-262518

Original issue reported on code.google.com by jeff.lau...@gmail.com on 7 Oct 2010 at 4:35

@GoogleCodeExporter
Copy link
Author

Original comment by jeff.lau...@gmail.com on 7 Oct 2010 at 4:37

Attachments:

@GoogleCodeExporter
Copy link
Author

This is due to an infinite recursion in Mock.__getattr__.  Add this to the top 
to fix the problem:

    def __getattr__(self, name):
        if name == "_methods":
            raise AttributeError(name)

Original comment by ned...@gmail.com on 7 Oct 2010 at 2:12

@GoogleCodeExporter
Copy link
Author

Original comment by fuzzyman on 7 Oct 2010 at 2:23

  • Changed state: Accepted
  • Added labels: Milestone-Release0.7

@GoogleCodeExporter
Copy link
Author

PS: a longer write-up of the issue: 
http://nedbatchelder.com/blog/201010/surprising_getattr_recursion.html

Original comment by ned...@gmail.com on 8 Oct 2010 at 10:35

@GoogleCodeExporter
Copy link
Author

Fixed, but the test is a bit brutal (call sys.setrecursionlimit(sys.maxint) and 
copying a Mock segfaults without the fix). I did try the sys.settrace trick, 
but for some reason that didn't work (the trace function wasn't removed during 
the test even after the recursion).

Original comment by fuzzyman on 18 Oct 2010 at 9:36

  • Changed state: Fixed

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

1 participant