Quantcast
Channel: How to do unit testing of functions writing files using Python's 'unittest' - Stack Overflow
Browsing latest articles
Browse All 8 View Live

Answer by Herbert Lee for How to do unit testing of functions writing files...

If you can use it, I'd strongly recommend using the following library: http://pyfakefs.orgpyfakefs creates an in-memory fake filesystem, and patches all filesystem accesses with accesses to the fake...

View Article



Answer by Enrico Marchesin for How to do unit testing of functions writing...

I always try to avoid writing files to disk, even if it's a temporary folder dedicated to my tests: not actually touching the disk makes your tests much faster, especially if you interact with files a...

View Article

Answer by tbc0 for How to do unit testing of functions writing files using...

import filecmpThenself.assertTrue(filecmp.cmp(path1, path2))

View Article

Answer by jan for How to do unit testing of functions writing files using...

Based on suggestions I did the following.class MyTestCase(unittest.TestCase): def assertFilesEqual(self, first, second, msg=None): first_f = open(first) first_str = first_f.read() second_f =...

View Article

Answer by gotgenes for How to do unit testing of functions writing files...

I prefer to have output functions explicitly accept a file handle (or file-like object), rather than accept a file name and opening the file themselves. This way, I can pass a StringIO object to the...

View Article


Answer by Don Kirkby for How to do unit testing of functions writing files...

You could separate the content generation from the file handling. That way, you can test that the content is correct without having to mess around with temporary files and cleaning them up afterward.If...

View Article

Answer by Ned Batchelder for How to do unit testing of functions writing...

The simplest thing is to write the output file, then read its contents, read the contents of the gold (expected) file, and compare them with simple string equality. If they are the same, delete the...

View Article

How to do unit testing of functions writing files using Python's 'unittest'

I have a Python function that writes an output file to disk.I want to write a unit test for it using Python's unittest module.How should I assert equality of files? I would like to get an error if the...

View Article

Browsing latest articles
Browse All 8 View Live




Latest Images