unittest weirdness

Ethan Furman ethan at stoneleaf.us
Tue Mar 11 21:58:17 CET 2014

So I finally got enough data and enough of an understanding to write some unit tests for my code.

These aren't the first unit tests I've written, but the behavior I'm getting is baffling.

I'm using 2.7.4 and I'm testing some routines which attempt to interpret data from a flat file and create a new flat 
file for later programmatic consumption.

The weird behavior I'm getting:

   - when a test fails, I get the E or F, but no summary at the end
     (if the failure occurs in setUpClass before my tested routines
     are actually called, I get the summary; if I run a test method
     individually I get the summary)

   - I have two classes, but only one is being exercised

   - occasionally, one of my gvim windows is unceremoniously killed
    (survived only by its swap file)

I'm running the tests under sudo as the routines expect to be run that way.

Anybody have any ideas?


--snippet of code--

from VSS.path import Path
from unittest import TestCase, main as Run
import wfbrp

class Test_wfbrp_20140225(TestCase):

     def setUpClass(cls):
         cls.pp = wfbrp.PaymentProcessor(

     def test_xxx_1(self):
         p = self.pp.lockbox_payments[0]
         # affirm we have what we're expecting
                 (p.payer, p.ck_num, p.credit),
                 ('a customer', '010101', 10000),
         self.assertEqual(p.invoices.keys(), ['XXXXXXXXXXX'])
         self.assertEqual(p.invoices.values()[0].amount, 10000)
         # now make sure we get back what we're expecting
         np, b = self.pp._match_invoices(p)
         missing = []
         for inv_num in ('123456', '789012', '345678'):
             if inv_num not in b:
         if missing:
             raise ValueError('invoices %r missing from batch' % missing)

More information about the Python-list mailing list