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

Fix unstubbing of __new__ #6

Open
awestendorf opened this issue Jul 29, 2013 · 4 comments
Open

Fix unstubbing of __new__ #6

awestendorf opened this issue Jul 29, 2013 · 4 comments

Comments

@awestendorf
Copy link
Member

This seems to be working. In writing tests for https://github.com/agoragames/torus , it seems that an expectation on the Timeseries type was not cleaned up properly, and resulted in the following error for a test that didn't try to mock out that constructor.

======================================================================
ERROR: test_match_list (test.unit.schema_test.SchemaTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/aaron/.virtualenvs/torus/local/lib/python2.7/site-packages/chai/chai.py", line 57, in wrapper
    func(self, *args, **kwargs)
  File "/home/aaron/projects/torus/test/unit/schema_test.py", line 70, in test_match_list
    s = Schema('name', config)
  File "/home/aaron/projects/torus/torus/schema.py", line 53, in __init__
    self.timeseries = Timeseries(self._client, **config)
TypeError: unbound method __new__() must be called with Timeseries instance as first argument (got type instance instead)
@ajferrick
Copy link

Are you finding that this is still an issue, because I'm seeing something similar. I use mock on a static function, and in subsequent tests I see the function is added back to the class as an unbounded function. When I invoke the function in the subsequent tests, I get the same TypeError: unbound method... result.

@awestendorf
Copy link
Member Author

Are you using @staticmethod? If so, I don't think that's a case that's currently tested. Each one of those require some special handling, so likely there needs to be a test written, and then a new StubStatic implementation.

@ajferrick
Copy link

Yeah, I was using @staticmethod. Is this something you'd likely be working on soon, or should I explore it myself and PR?

@awestendorf
Copy link
Member Author

@ajferrick This commit 1a3d80c may have what you need, as a staticmethod looks identical to an unbound method in Python3. That may not work specifically with mock, but expect should work so long as you use it in the form expect(obj, 'staticmethod_name').

Sorry for the late response, open source dropped off my radar as we had a very busy end of year.

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

No branches or pull requests

2 participants