paulocheque / django-dynamic-fixture

A complete library to create dynamic model instances for testing purposes.
http://django-dynamic-fixture.readthedocs.io/
Other
391 stars 67 forks source link

Remove created files #21

Closed camilonova closed 11 years ago

camilonova commented 11 years ago

If i create a test, and use the dynamic fixture on a model that contains a FileField, it creates a file, and after the test ends the created file is not removed from the file system.

Could you add some way to remove those images?

paulocheque commented 11 years ago

This is a very good suggestion. Do you have anything in mind to implement this? Maybe using a unique directory for all DDF files..

Could you try the FileSystemDjangoTestCase? https://github.com/paulocheque/django-dynamic-fixture/wiki/Documentation#wiki-filesystem

paulocheque commented 11 years ago

There is a known issue in FileSystemDjangoTestCase on Windows. It may be related with the Windows Registry according to https://github.com/valdergallo.

remove_temp_file os.remove(filepath) WindowsError: [Error 32] The process cannot access the file because it is being used by another process:

valdergallo commented 11 years ago

We have 2 options to implement this: 1 - Change all create files to StringIO 2 - Change by default on ddf to use settings.DEFAULT_FILE_STORAGE=FileSystemStorage(location=TEMP_PATH)

valdergallo commented 11 years ago

Because Django use by default FileSystemStorage location on MEDIA_ROOT, all tests files will be created on STATIC directory. But DDF just try delete files in TEMP_PATH.

def fdf_teardown(self):
    if self.TEAR_DOWN_ENABLED:
        while self.files:
            self.remove_temp_file(self.files.keys()[0])
        while self.directories:
            self.remove_temp_directory(self.directories[0])
paulocheque commented 11 years ago

https://pypi.python.org/pypi/django-dynamic-fixture/1.6.5

paulocheque commented 11 years ago

Thanks for reporting. Thanks for the pull request!