[TIP] Struggling with pymock

Tobias Roth misc.lists at fsck.ch
Fri Sep 7 14:14:17 PDT 2007


I am struggling with the basics of pymock. Here is a simplified example
class I'd like to test:

class Example(object):
	def __init__(self, cf):
		self.conffile = cf
		f = open(self.conffile)
		# read and assign

What I'd like to test is whether the constructor correctly opens a file
and reads and assigns its contents to some member variables.

What I'd do with conventional unit testing would be to create a fake
conffile with some data, have it read by __init__ and then compare what
has been read with what I set up.

Now what I imagined to do with pymock was to stub out
__builtins__.open(). But I could't get pymock to handle the
self.conffile argument to open() correctly.

I feel like I am looking at the whole pymock testing from the wrong way,
since I can't get such a simple example to work. Can someone enlighten me?


More information about the testing-in-python mailing list