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 7087313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:39:32+00:00 2026-05-28T07:39:32+00:00

Mocker has a patching function that it says allows you to replace a class,

  • 0

Mocker has a patching function that it says allows you to replace a class, so that all instances of this class will be patched through to your mock.

I am trying to do some testing of a function that uses pysnmp, and I am trying to mock out the calls that use this library.

In my code I do this:

from pysnmp.entity.rfc3413.oneliner import cmdgen
commandGen = cmdgen.CommandGenerator()
... code that uses commandGen

In my test I tried:

from mocker import Mocker
mocker = Mocker()
commandGenMock = mocker.patch(cmdgen.CommandGenerator)
commandGenMock.doSomething()
mocker.replay()

and I get the following:

Traceback (most recent call last):
  File "<pyshell#9>", line 1, in <module>
     mocker.replay()
  File "build\bdist.win32\egg\mocker.py", line 578, in replay
     event.replay()
  File "build\bdist.win32\egg\mocker.py", line 1757, in replay
    task.replay()
  File "build\bdist.win32\egg\mocker.py", line 2197, in replay
    self.is_monitoring))
  File "build\bdist.win32\egg\mocker.py", line 2157, in patch_attr
    setattr(obj, attr, value)
TypeError: can't set attributes of built-in/extension type 'classobj'

Can anyone shed any light on what I am doing wrong?

  • 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-05-28T07:39:33+00:00Added an answer on May 28, 2026 at 7:39 am

    Just a tip, in your test, try to mock the instance instead of the class:

    from mocker import Mocker
    mocker = Mocker()
    commandGen = cmdgen.CommandGenerator()
    commandGenMock = mocker.patch(commandGen)
    commandGenMock.doSomething()
    mocker.replay()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code to be tested abstract class Parent { public function getSomething(){} //this has
I have a class Foo that has a method Bar makeBar(String id) . As
I understand the need to test a class that has logic (for instance, one
This may be a painfully simply question for which I will be mocked but
I have a class which has a internal method and i want to mock
I have a stored procedure that has a bunch of input and output parameters
I know the first part of this question has been asked before , but
I am developing tests for an application. There's a method that has a params
I have a security rule that a newly registered user has full permissions over
I took a method from this post (accepted answer code) that serializes object so

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.