Syntax error in python unittest script

Terry Reedy tjreedy at
Wed Sep 24 23:39:38 CEST 2014

On 9/24/2014 3:33 PM, Milson Munakami wrote:

> I am learning to use unittest with python

[way too long example]

> File "", line 44
>      def cleanup(self, success):
>        ^
> SyntaxError: invalid syntax

A common recommendation is to find the *minimal* example that exhibits 
the problem.  (Start with commenting out everything after the code in 
the traceback, then at least half the code before it. Etc.) That means 
that removing or commenting out a single statememt and the problem 
disappears.  In compound statements, you may need to insert 'pass' to 
not create a new problem.

If you had done that, you would have reduced your code to something like

class testFirewall( unittest.TestCase ):
	def tearDown(self):
		if self.reportStatus_:"=== Test %s completed normally (%d sec)", self.name_, 
	def cleanup(self, success):
		sys.excepthook = sys.__excepthook__

At that point, replacing "" with "pass" would have made 
it clear that the problem was with the replaced statement.

Terry Jan Reedy

More information about the Python-list mailing list