I have two directories, output/ and sample/. output/ is filled with 400 files that are generated automatically by a batch procedure. sample/ contains the same files, pregenerated and validated manually one by one.
I need to write a unit test that verifies that all files in output/ are identical to those in sample/.
I wrote:
import unittest
import glob
import os.path
class TestReports(unittest.TestCase):
def setUp(self):
# Discover reports
self.reports = glob.glob('sample/*.csv')
def test_all_reports(self):
for sample_report in self.reports:
output_report = 'output/' + os.path.basename(sample_report)
self.assertFileEquals(sample_report, output_report)
def assertFileEquals(self, fname1, fname2):
with open(fname1) as fh1:
with open(fname2) as fh2:
self.assertEquals(fh1.read(), fh2.read(), "%s and %s are identical" % (fname1, fname2)
The above fails at the first different file, and only produces 1 line of output in the junit report ("at least 1 file is different").
What I need is to generate a junit report that shows 400 independent tests, with the test description automatically generated from the file name. How do I do that with unittest/unittest2/nosetests?