Am 6. Juli 2010 16:43 schrieb Luca Bigliardi <[email protected]>:
> +class TestMlockallWithNoCtypes(unittest.TestCase):
> +  """Whether Mlockall() raises an error if ctypes is not present.
> +
> +  """
> +
> +  def setUp(self):
> +    self.old_ctypes = utils.ctypes
> +    utils.ctypes = None
> +
> +  def tearDown(self):
> +    utils.ctypes = self.old_ctypes

Don't change other modules' internals in unittests as doing so can
cause bugs very, very difficult to debug. Instead, do something like
this:

def Mlockall(_ctypes=ctypes):
  if _ctypes:
    _ctypes.….mlockall()

Then you can call Mlockall(_ctypes=None) and
Mlockall(_ctypes=MockCtypes()) in the unittests.

Michael

Reply via email to