[CentralOH] Testing Seams

Mark Erbaugh mark at microenh.com
Mon Oct 11 03:13:24 CEST 2010


I've come up with a scheme for inserting a test seam into some Python code that seems to work.

Here's a simplified example showing the concept.

module under test:

# --------------------
# mut.py

import setup  # defines A

def function():
	return setup.A 

# -------------------

During development the value of setup.A will change.

Here's the unit test code

# -----------------

import unittest
import setup

setup.A = 10

import mut

	self.asertEquals(10, mut.function())

# ----------------

Of course, in reality, function() does something more complex.  The 'trick' to the above code is that setup is only loaded the first time it is imported (in the unit test module). The changes made to setup will be seen when setup is imported in mut.py

Is this an appropriate testing seam?


More information about the CentralOH mailing list