derwiki-adroll / mock

Automatically exported from code.google.com/p/mock
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

AttributeError: '_SpecState' object has no attribute 'reset_mock' #162

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. in a unit test I patched the logging module in the module under test
    def setUp(self):
        ....
        logging_patch = mock.patch("mcp.metrics.collectors.logging", 
            autospec=True)
        self.logging_mock = logging_patch.start()
        self.addCleanup(logging_patch.stop)

        self.logger_mock = mock.Mock(spec_set=logging.Logger)
        self.logging_mock.getLogger.return_value = self.logger_mock

2. Later in the test function ran these two lines
        self.logger_mock.reset_mock()
        self.logging_mock.reset_mock()
3.

What is the expected output? What do you see instead?

I expected both lines to succeed. Only the first did, second resulted in the 
error below:

Traceback (most recent call last):
  File "/packages/mcp_metrics/tests/tests/test_metrics.py", line 122, in setUp
    self._new_timer()
  File "/packages/mcp_metrics/tests/tests/test_metrics.py", line 129, in _new_timer
    self.logging_mock.reset_mock()
  File "/.dev-env/lib/python2.7/site-packages/mock.py", line 666, in reset_mock
    child.reset_mock()
AttributeError: '_SpecState' object has no attribute 'reset_mock'

What version of the product are you using? On what operating system?

mock==0.8.0

(.dev-env)aarons-MBP-2011:ops aaron$ python -V
Python 2.7.1

osx 10.7.4

Please provide any additional information below.

Original issue reported on code.google.com by aaron.th...@gmail.com on 31 May 2012 at 3:33

GoogleCodeExporter commented 9 years ago
Thanks for reporting this. I can fix this in 1.0.

Original comment by fuzzyman on 9 Jun 2012 at 2:36

GoogleCodeExporter commented 9 years ago
Now fixed on trunk. In addition reset_mock now resets magic method mocks (which 
it didn't previously).

Original comment by fuzzyman on 9 Jun 2012 at 2:49

GoogleCodeExporter commented 9 years ago

Original comment by fuzzyman on 9 Jun 2012 at 2:53

GoogleCodeExporter commented 9 years ago
Thank you.
Aaron

Original comment by aaron.th...@gmail.com on 10 Jun 2012 at 7:42