I have some unitest is doing something like:
_files = ('test1.txt','test2.txt'......)
setUp(){
//create test files
for f in _files:
f = open(f, 'w')
f.close()
}
tearDown(){
for f in _files:
if os.path.exists(f):
os.remove(f)
}
But some people told me it’s not a good practice to do I/O in unitest, is it true?
I don’t think it’s necessarily bad to perform I/O in a unit test.
The only caveat is that if your unit test relies on some pre-existing data files in order to do its thing, then the files should be considered part of the unit test (and therefore version controlled etc).
P.S. Have you tried asking those who gave you this advice for specific reasons behind the recommendation?