Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8057717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:07:18+00:00 2026-06-05T09:07:18+00:00

My issue is quite simple: I’m having a bunch of unit tests using pymox.

  • 0

My issue is quite simple: I’m having a bunch of unit tests using pymox. When I add a new test that fails, most of the time a whole lot of others fail as well. How can I prevent that from happening?

For example, I have a simple script for which I have two unit tests:

def test_main_returnsUnknown_ifCalculator_returnsMinus1(self):
    m=mox.Mox()
    m.StubOutWithMock(check_es_insert,"getArgs")
    check_es_insert.getArgs(\
        'Nagios plugin for checking the total number of documents stored in Elasticsearch')\
        .AndReturn({ 'critical' : 7, 'warning' : 5, 'address' : 'myhost:1234', 'file' : '/tmp/bla'})
    ################
    #some other mocking here, not relevant, I think
    ################
    m.ReplayAll()
    #now let's test
    check_es_docs.main()
    #verify and cleanup
    m.UnsetStubs()
    m.VerifyAll()
    m.ResetAll()
def test_main_doesWhatPrintAndExitSays_inNormalConditions(self):
    m=mox.Mox()
    m.StubOutWithMock(check_es_insert,"getArgs")
    check_es_insert.getArgs(\
        'Nagios plugin for checking the total number of documents stored in Elasticsearch')\
        .AndReturn({ 'critical' : 7, 'warning' : 5, 'address' : 'myhost:1234', 'file' : '/tmp/bla'})
    ################
    #some other mocking here, not relevant, I think
    ################
    m.ReplayAll()
    #now let's test
    check_es_docs.main()
    #verify and clean up
    m.UnsetStubs()
    m.VerifyAll()
    m.ResetAll()

Normally, both tests pass, but if I sneak in a typo on my second tests, I get this output when running the tests:

$ ./check_es_docs.test.py
FE
======================================================================
ERROR: test_main_returnsUnknown_ifCalculator_returnsMinus1 (__main__.Main)
If it can't get the current value from ES, print an error message and exit 3
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./check_es_docs.test.py", line 13, in test_main_returnsUnknown_ifCalculator_returnsMinus1
    m.StubOutWithMock(check_es_insert,"getArgs")
  File "/usr/local/lib/python2.7/dist-packages/mox-0.5.3-py2.7.egg/mox.py", line 312, in StubOutWithMock
    raise TypeError('Cannot mock a MockAnything! Did you remember to '
TypeError: Cannot mock a MockAnything! Did you remember to call UnsetStubs in your previous test?

======================================================================
FAIL: test_main_doesWhatPrintAndExitSays_inNormalConditions (__main__.Main)
If getCurrent returns a positive value, main() should print the text and exit with the code Calculator.printandexit() says
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./check_es_docs.test.py", line 69, in test_main_doesWhatPrintAndExitSays_inNormalConditions
    check_es_docs.main()
  File "/home/radu/check_es_docs.py", line 25, in main
    check_es_insert.printer("Total number of documents in Elasticsearch is %d | 'es_docs'=%d;%d;%d;;" % (result,result,cmdline['warning'],cmdline['critical']))
  File "/usr/local/lib/python2.7/dist-packages/mox-0.5.3-py2.7.egg/mox.py", line 765, in __call__
    return mock_method(*params, **named_params)
  File "/usr/local/lib/python2.7/dist-packages/mox-0.5.3-py2.7.egg/mox.py", line 1002, in __call__
    expected_method = self._VerifyMethodCall()
  File "/usr/local/lib/python2.7/dist-packages/mox-0.5.3-py2.7.egg/mox.py", line 1060, in _VerifyMethodCall
    raise UnexpectedMethodCallError(self, expected)
UnexpectedMethodCallError: Unexpected method call.  unexpected:-  expected:+
- printer.__call__("Total number of documents in Elasticsearch is 3 | 'es_docs'=3;5;7;;") -> None
?                           -

+ printer.__call__("Total nuber of documents in Elasticsearch is 3 | 'es_docs'=3;5;7;;") -> None

----------------------------------------------------------------------
Ran 2 tests in 0.002s

FAILED (failures=1, errors=1)

The first test should have passed with no error, since it wasn’t changed a bit. check_es_insert.getArgs() shouldn’t be a MockAnything instance, and I didn’t forget to call UnsetStubs. I’ve searched quite a lot and I didn’t find other people with the same problem. So I guess I’m missing something pretty obvious…

Additional info:

  • check_es_docs is the script I’m testing
  • check_es_insert is another script from which I’m importing a lot of stuff
  • I’ve tried putting UnsetStubs() after VerifyAll() with the same results
  • I’ve tried initializing the mox.Mox() object from the SetUp method, and also putting the cleanup stuff in TearDown, with the same results
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:07:21+00:00Added an answer on June 5, 2026 at 9:07 am

    I would recommend putting all of your tests into test classes that extend TestCase and then add in an UnsetStubs in the tearDown method:

    from unittest import TestCase
    import mox
    
    class MyTestCasee(TestCase):
      def __init__(self, testCaseName):
        self.m = mox.Mox()
        TestCase.__init__(self, testCaseName)
    
      def tearDown(self):
        self.m.UnsetStubs()
    
    
    def test_main_returnsUnknown_ifCalculator_returnsMinus1(self):
      self.m.StubOutWithMock(check_es_insert,"getArgs")
      check_es_insert.getArgs(\
        'Nagios plugin for checking the total number of documents stored in Elasticsearch')\
        .AndReturn({ 'critical' : 7, 'warning' : 5, 'address' : 'myhost:1234', 'file' : '/tmp/bla'})
      ################
      #some other mocking here, not relevant, I think
      ################
      self.m.ReplayAll()
      #now let's test
      check_es_docs.main()
      #verify and cleanup
      self.m.VerifyAll()
    
    def test_main_doesWhatPrintAndExitSays_inNormalConditions(self):
      self.m.StubOutWithMock(check_es_insert,"getArgs")
      check_es_insert.getArgs(\
          'Nagios plugin for checking the total number of documents stored in Elasticsearch')\
          .AndReturn({ 'critical' : 7, 'warning' : 5, 'address' : 'myhost:1234', 'file' : '/tmp/bla'})
      ################
      #some other mocking here, not relevant, I think
      ################
      self.m.ReplayAll()
      #now let's test
      check_es_docs.main()
      #verify and clean up
      self.m.VerifyAll()
      self.m.ResetAll()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a performance issue regarding a quite simple query that run for more
I'm quite new to ruby and I'm blocking on this simple issue: I have
I'm having a little issue getting quite a simple bash script running. The part
My issue is quite simple I think : I would like to be able
My issue here is quite simple : i'm trying to use the jQuery validate
I have an nHibernate query issue that looks quite straight forward, but I can't
I'm having quite the brainbuster of an issue right now. I am trying to
I have a simple, general question regarding a real small issue that bothers me:
My issue is quite simple, I hava a generic parent class with the following
I'm having a simple issue where my C executable is crashing after attempting to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.