glasser / pymox

Automatically exported from code.google.com/p/pymox
Apache License 2.0
7 stars 11 forks source link

Stub out os.stat raises exception when run with nosetests #56

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a minimum testcase, called Test.py

import mox
import unittest
import os

class TestExample(unittest.TestCase):
    def test_stat(self):
        mock = mox.Mox()
        mock.StubOutWithMock(os, 'stat')
        stat = mock.CreateMockAnything()
        os.stat('a').AndReturn(stat)

        mock.ReplayAll()
        print os.stat('a')
        mock.VerifyAll()
        mock.UnsetStubs()

2. nosetests
3. Exception is raised because nosetests is using os.stat, which is stubbed out
Traceback (most recent call last):
  File "/usr/local/bin/nosetests", line 9, in <module>
    load_entry_point('nose==1.2.1', 'console_scripts', 'nosetests')()
  File "/Library/Python/2.7/site-packages/nose/core.py", line 118, in __init__
    **extra_args)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/main.py", line 95, in __init__
    self.runTests()
  File "/Library/Python/2.7/site-packages/nose/core.py", line 197, in runTests
    result = self.testRunner.run(self.test)
  File "/Library/Python/2.7/site-packages/nose/core.py", line 61, in run
    test(result)
  File "/Library/Python/2.7/site-packages/nose/suite.py", line 176, in __call__
    return self.run(*arg, **kw)
  File "/Library/Python/2.7/site-packages/nose/suite.py", line 223, in run
    test(orig)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/suite.py", line 70, in __call__
    return self.run(*args, **kwds)
  File "/Library/Python/2.7/site-packages/nose/suite.py", line 74, in run
    test(result)
  File "/Library/Python/2.7/site-packages/nose/suite.py", line 176, in __call__
    return self.run(*arg, **kw)
  File "/Library/Python/2.7/site-packages/nose/suite.py", line 223, in run
    test(orig)
  File "/Library/Python/2.7/site-packages/nose/suite.py", line 176, in __call__
    return self.run(*arg, **kw)
  File "/Library/Python/2.7/site-packages/nose/suite.py", line 223, in run
    test(orig)
  File "/Library/Python/2.7/site-packages/nose/case.py", line 45, in __call__
    return self.run(*arg, **kwarg)
  File "/Library/Python/2.7/site-packages/nose/case.py", line 138, in run
    result.addError(self, err)
  File "/Library/Python/2.7/site-packages/nose/proxy.py", line 135, in addError
    self.result.addError(self.test, self._prepareErr(err))
  File "/Library/Python/2.7/site-packages/nose/result.py", line 61, in addError
    exc_info = self._exc_info_to_string(err, test)
  File "/Library/Python/2.7/site-packages/nose/result.py", line 187, in _exc_info_to_string
    return _TextTestResult._exc_info_to_string(self, err, test)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/result.py", line 164, in _exc_info_to_string
    msgLines = traceback.format_exception(exctype, value, tb)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/traceback.py", line 141, in format_exception
    list = list + format_tb(tb, limit)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/traceback.py", line 76, in format_tb
    return format_list(extract_tb(tb, limit))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/traceback.py", line 101, in extract_tb
    line = linecache.getline(filename, lineno, f.f_globals)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/linecache.py", line 14, in getline
    lines = getlines(filename, module_globals)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/linecache.py", line 40, in getlines
    return updatecache(filename, module_globals)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/linecache.py", line 80, in updatecache
    stat = os.stat(fullname)
  File "/Library/Python/2.7/site-packages/mox.py", line 1002, in __call__
    expected_method = self._VerifyMethodCall()
  File "/Library/Python/2.7/site-packages/mox.py", line 1049, in _VerifyMethodCall
    expected = self._PopNextMethod()
  File "/Library/Python/2.7/site-packages/mox.py", line 1035, in _PopNextMethod
    raise UnexpectedMethodCallError(self, None)
mox.UnexpectedMethodCallError: Unexpected method call Stub for <built-in 
function stat>.__call__('/Library/Python/2.7/site-packages/nose/case.py') -> 
None

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

Expected: pass
Real: the error message above

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

mox==0.5.3

OSX 10.8 and RHEL 6.3

Please provide any additional information below.

Original issue reported on code.google.com by eeso...@gmail.com on 12 Mar 2013 at 7:59