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

  • SEARCH
  • Home
  • 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 8762477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:32:29+00:00 2026-06-13T15:32:29+00:00

I am doing some unit testing and at some point I need to mock

  • 0

I am doing some unit testing and at some point I need to mock a super call to throw an error, for example:

@classmethod
def myfunc(cls, *args, **kwargs)
    try:
        super(MyClass, cls).my_function(args, kwargs)
    except MyException as e:
        #...

I am using the mocker library to mock my objects in general but I haven’t found a way to mock this.

  • 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-13T15:32:30+00:00Added an answer on June 13, 2026 at 3:32 pm

    I found a way, sort of hacky but it works, I’ll explain with my example, this is based on this response so thanks @kindall:

    def my_test(self):
        import __builtin__
        from mocker import Mocker, KWARGS, ARGS
    
        mymocker = mocker.mock()
        mymocker.my_function(ARGS, KWARGS)
        mocker.throw(MyException)
    
        def mysuper(*args, **kwargs):
            if args and issubclass(MyClass, args[0]):
                return mymocker
            return original_super(*args, **kwargs)
    
        __builtin__.original_super = super
        __builtin__.super = mysuper
    
        with mocker:
            MyClass.myfunc()
    

    so essentially what I do is check if the super call is from the class I want to mock, else just do a normal super.

    Hope this helps someone 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was doing some unit testing on code that could throw a number of
I was doing some unit testing at work and a peculiar error popped up
I'm doing some unit testing, and some of the code is checking to see
I am doing some unit testing for a DAO that works with postgresql. Some
I'm having a bit of trouble doing some unit-testing using moq. If I have
I found a strange problem while doing some unit-testing on Magento. I have a
In my current Rails 3 app, I'm doing some unit testing to make sure
I'm doing some unit testing, and mocking some properties using Moq . Now, this
I'm doing some unit tests where essentially I need the input stream to block
Currently I'm doing Unit testing of some project and all is fine except for

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.