mock with inheritance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lidiriel

    mock with inheritance

    Hello,

    i would like use a mock object for testing one class and its methods:
    Here my class :
    class Foo(Component):
    def __init__(self):
    self._db = self.env.get_db ()

    def foomethod(self, arg):
    .....

    But i don't know how to mock the class Component. Note that Component
    provide the attribut env.
    I use
    Pyhton mock module (author Dave Kirby's ) or
    mock (author Michael Foord (fuzzyman)) but if you have a generic
    solution i will adapt it to my problem.

    Thanks by advance and sorry for my poor english.

  • Ben Finney

    #2
    Re: mock with inheritance

    lidiriel <ludovic.mercie r@gmail.comwrit es:
    But i don't know how to mock the class Component. Note that Component
    provide the attribut env.
    I prefer to use the MiniMock framework
    <URL:http://cheeseshop.pyth on.org/pypi/MiniMock>.

    You don't need to specify what interface the mock object has. Its Mock
    objects will allow *any* attribute access, method or otherwise, and
    simply report what was done. You can then check that report to see if
    it matches what you expect; the author suggests that the existing
    standard-library 'doctest' module is ideal for such checking.

    --
    \ “It is the mark of an educated mind to be able to entertain a |
    `\ thought without accepting it.” —Aristotle |
    _o__) |
    Ben Finney

    Comment

    Working...