diff --git a/collectfast/strategies/base.py b/collectfast/strategies/base.py index fdf4590..1705b3f 100644 --- a/collectfast/strategies/base.py +++ b/collectfast/strategies/base.py @@ -3,10 +3,10 @@ import hashlib import logging import mimetypes +import pydoc import warnings from functools import lru_cache from io import BytesIO -from pydoc import locate from typing import ClassVar from typing import Generic from typing import Optional @@ -140,7 +140,7 @@ def get_gzipped_local_file_hash(self, uncompressed_file_hash, path, contents): def load_strategy(klass: Union[str, type, object]) -> Type[Strategy[Storage]]: if isinstance(klass, str): - klass = locate(klass) + klass = pydoc.locate(klass) if not isinstance(klass, type) or not issubclass(klass, Strategy): raise ImproperlyConfigured( "Configured strategies must be subclasses of %s.%s" @@ -157,11 +157,11 @@ def load_strategy(klass: Union[str, type, object]) -> Type[Strategy[Storage]]: def _resolves_to_subclass(subclass_ref: str, superclass_ref: str) -> bool: try: - subclass = locate(subclass_ref) + subclass = pydoc.locate(subclass_ref) assert isinstance(subclass, type) - superclass = locate(superclass_ref) + superclass = pydoc.locate(superclass_ref) assert isinstance(superclass, type) - except (ImportError, AssertionError) as e: + except (ImportError, AssertionError, pydoc.ErrorDuringImport) as e: logger.debug("Failed to import %s: %s" % (superclass_ref, e)) return False return issubclass(subclass, superclass) diff --git a/conftest.py b/conftest.py index 0a82373..8a4f616 100644 --- a/conftest.py +++ b/conftest.py @@ -1,6 +1,5 @@ import os import shutil -from functools import partial import pytest from django.conf import settings @@ -8,9 +7,12 @@ @pytest.fixture(autouse=True) def create_test_directories(): - paths = (settings.STATICFILES_DIRS[0], settings.STATIC_ROOT) - map(partial(os.makedirs, exist_ok=True), paths) + paths = (settings.STATICFILES_DIRS[0], settings.STATIC_ROOT, settings.MEDIA_ROOT) + for path in paths: + if not os.path.exists(path): + os.makedirs(path) try: yield finally: - map(shutil.rmtree, paths) + for path in paths: + shutil.rmtree(path)