Lesson 5

Now that you know all there is to know about svnmock, let's talk about how to get the most of that knowledge.

  • It's important that you import svnmock before importing any modules that make use of svn.* modules. svnmock plays some games with sys.modules in order to masquerade as svn, and it needs to pull these tricks before svn.* modules show up.

    For all the gory details on how these tricks work, see the reference section on API emulation.

  • You'll notice that you tend to repeat a lot of boilerplate session.add_command(fs.... calls; these make good candidates for refactoring into functions or methods in your test suite.

  • You remember all those calls to mock.add_command, mock.add_error, etc? Those are just convenience functions that redirect the call to the default MockSession object in svnmock.mock.active_session. The convenience functions are offered so that you don't have to explicitly create and reference a MockSession object on your own.

    On the other hand, if you want to create your own MockSession instances, the class lives in svnmock.mock. To make another instance the active session, use the MockSession.make_active instance method.

svnmock