0

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?

Charles
  • 50,943
  • 13
  • 104
  • 142
crusaderky
  • 2,552
  • 3
  • 20
  • 28
  • 1
    On top of my head: [nose-parameterized](https://pypi.python.org/pypi/nose-parameterized/0.3.3) and [nose itself](https://nose.readthedocs.org/en/latest/writing_tests.html#test-generators) – J0HN May 08 '14 at 11:16
  • 1
    You can generate test case functions, as explained in [the answer to this question](http://stackoverflow.com/q/32899/1298153) – m01 May 08 '14 at 21:02

0 Answers0