diff --git a/setup.py b/setup.py index 3d03fbe..5ad75cc 100755 --- a/setup.py +++ b/setup.py @@ -1,27 +1,46 @@ #!/usr/bin/env python +import os import sys from setuptools import setup, find_packages -from setuptools.command.test import test as TestCommand -class PyTest(TestCommand): - user_options = [('pytest-args=', 'a', "Arguments to pass to py.test")] +def execute_tests(): + """ + Standalone django model test with a 'memory-only-django-installation'. + You can play with a django model without a complete django app installation. + http://www.djangosnippets.org/snippets/1044/ + """ + import django - def initialize_options(self): - TestCommand.initialize_options(self) - self.pytest_args = [] + sys.exc_clear() - def finalize_options(self): - TestCommand.finalize_options(self) - self.test_args = [] - self.test_suite = True + os.environ["DJANGO_SETTINGS_MODULE"] = "django.conf.global_settings" + from django.conf import global_settings + + global_settings.INSTALLED_APPS = () + global_settings.MIDDLEWARE_CLASSES = () + global_settings.SECRET_KEY = "not-very-secret" + + global_settings.DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + } + } + + global_settings.CACHES = { + 'default': { + 'BACKEND': 's3cache.AmazonS3Cache', + } + } + + from django.test.utils import get_runner + test_runner = get_runner(global_settings) + + test_runner = test_runner() + failures = test_runner.run_tests(['s3cache']) + sys.exit(failures) - def run_tests(self): - #import here, cause outside the eggs aren't loaded - import pytest - errno = pytest.main(self.pytest_args) - sys.exit(errno) with open('README.rst') as file: long_description = file.read() @@ -48,7 +67,7 @@ def run_tests(self): ], 'zip_safe' : False, 'install_requires' : ['boto','django-storages>=1.1.8','Django'], - 'cmdclass' : {'test': PyTest}, + 'test_suite' : '__main__.execute_tests', } if (len(sys.argv) >= 2) and (sys.argv[1] == '--requires'): diff --git a/tests/test_one.py b/tests/test_one.py deleted file mode 100755 index 2e73cec..0000000 --- a/tests/test_one.py +++ /dev/null @@ -1,15 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import unittest - -dirname = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(dirname, "..")) - -class TestOne(unittest.TestCase): - def test_simple(self): - self.assertTrue(1 == 1) - -if __name__ == '__main__': - unittest.main()