whitenoise: slowed tests

Adding the whitenoise middleware can greatly slow down your tests. If you have processes static previously and your static directory is full of static files. Then the middleware, on each test method, process the list of files over and over. So your tests are now slowed by a function of how many static files you have.

On startup this is called:

    def update_files_dictionary(self, root, prefix):
        for directory, _, filenames in os.walk(root, followlinks=True):
            for filename in filenames:
                path = os.path.join(directory, filename)
                url = prefix + os.path.relpath(path, root).replace('\\', '/')
                self.files[url] = self.get_static_file(path, url)

And if you have thousands of static files, this will slow it down.

Perhaps this list could be lazy loaded on first call rather than init.

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 19 (8 by maintainers)

Most upvoted comments

Also perhaps mentioning in the documentation that it’s recommended to disabling file scanning during tests?