Issue 56 in pymox: Stub out os.stat raises exception when run with nosetests

21 views
Skip to first unread message

codesite...@google.com

unread,
Mar 12, 2013, 3:59:15 AM3/12/13
to mox-d...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 56 by eeso...@gmail.com: Stub out os.stat raises exception when
run with nosetests
http://code.google.com/p/pymox/issues/detail?id=56

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.


--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages