python unit testing os.remove fails file system -


A bit of testing on a function that tries to open a new file, but if the file already exists . When the function runs properly, a new file is created, so I want to delete it after running each test, but it does not work:

  class MyObject_Initialization (unittest.TestCase) ): Def setUp (self): If os.path.exists (TEMPORARY_FILE_NAME): try: os.remove (TEMPORARY_FILE_NAME) except for WindowsError: #TODO: can not detect it to fix ... # time Sleep (3) # Self.setUp () # It just passes through the ends of DEF Tyrundo (self): self.setUp ()  

Any thoughts? Throwing Windows error suggest that the file is in use ... can it be that the tests are being run in parallel threads?

I have read elsewhere that it is 'bad behavior' to use the file system in unit testing, but actually ? Surely there is a way of saying that there is no permission to dummy the file system?

If you are just looking for a temporary file, take a look - clean it yourself -up all should handle


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -