diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 4f6c9c4..0c182a8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,7 +15,7 @@ jobs: strategy: matrix: python-version: ['3.9', '3.10', '3.11', '3.12'] - django-version: ['3.2', '4.2'] + django-version: ['4.2'] steps: # ソースコードをチェックアウト diff --git a/CHANGES.rst b/CHANGES.rst index e0e1606..e60d90e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,6 +1,14 @@ ChangeLog ========= +0.50 (2024-08-XX) +=================== + +Incompatible Changes: + +* Drop Django3.2&Celery5.2 +* Migrate from ``python setup.py test`` to ``pytest`` + 0.49 (2024-02-XX) =================== diff --git a/README.rst b/README.rst index 8e43d6f..06681bb 100644 --- a/README.rst +++ b/README.rst @@ -8,8 +8,8 @@ Requirements ============ * Python (3.9, 3.10, 3.11, 3.12) -* Celery (5.2, 5.3) -* Django (3.2, 4.2) +* Celery (5.3) +* Django (4.2) * six Links diff --git a/beproud/__init__.py b/beproud/__init__.py index 1a79358..e69de29 100644 --- a/beproud/__init__.py +++ b/beproud/__init__.py @@ -1,7 +0,0 @@ -# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages -try: - __import__('pkg_resources').declare_namespace(__name__) -except ImportError: - from pkgutil import extend_path - __path__ = locals()['__path__'] # make PyFlakes happy - __path__ = extend_path(__path__, __name__) diff --git a/beproud/django/__init__.py b/beproud/django/__init__.py index 1a79358..e69de29 100644 --- a/beproud/django/__init__.py +++ b/beproud/django/__init__.py @@ -1,7 +0,0 @@ -# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages -try: - __import__('pkg_resources').declare_namespace(__name__) -except ImportError: - from pkgutil import extend_path - __path__ = locals()['__path__'] # make PyFlakes happy - __path__ = extend_path(__path__, __name__) diff --git a/pyproject.toml b/pyproject.toml index bc875a9..ea45ab3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "bpnotify" -version = "0.49" +version = "0.50" authors = [ { name="BeProud Inc.", email="project@beproud.jp" }, ] @@ -22,13 +22,12 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Framework :: Django", - "Framework :: Django :: 3.2", "Framework :: Django :: 4.2", "Intended Audience :: Developers", "Environment :: Plugins", "Topic :: Software Development :: Libraries :: Python Modules", ] -dependencies = ["Django>=3.2", "six", "Celery"] +dependencies = ["Django>=4.2", "six", "Celery"] [project.urls] Homepage = "https://github.com/beproud/bpnotify/" diff --git a/setup.py b/setup.py deleted file mode 100644 index 14667d9..0000000 --- a/setup.py +++ /dev/null @@ -1,3 +0,0 @@ -from setuptools import setup - -setup(test_suite="tests.main") diff --git a/test_settings.py b/test_settings.py index 240e1cd..c2f24b9 100644 --- a/test_settings.py +++ b/test_settings.py @@ -1,3 +1,6 @@ +import os +import celery + # Django3では、標準のdjango.conf.global_settingsの定数をオーバーライドすると例外が発生する場合がある。 # https://github.com/django/django/blob/70035fb0444ae7c01613374212ca5e3c27c9782c/django/conf/__init__.py#L188 # そのため、testではdjango.conf.global_settingsを直接利用せず、このtest用settings定数を使用する。 @@ -9,12 +12,6 @@ 'beproud.django.notify', ) -# kombu.exceptions.EncodeError: Object of type User is not JSON serializable エラーを抑止する -# (参考) -# https://github.com/celery/celery/issues/5922 -# https://stackoverflow.com/questions/49373825/kombu-exceptions-encodeerror-user-is-not-json-serializable -CELERY_TASK_SERIALIZER = "pickle" - DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', @@ -22,7 +19,6 @@ } } -import os BASE_PATH = os.path.dirname(__file__) TEMPLATES = [ @@ -33,8 +29,7 @@ ], }, ] - -CELERY_TASK_ALWAYS_EAGER = True +USE_TZ = False # For Django 5.0+ BPNOTIFY_MEDIA = { "news": { @@ -55,6 +50,16 @@ } BPNOTIFY_SETTINGS_STORAGE = 'beproud.django.notify.storage.db.DBStorage' -# The name of the class to use to run the test suite -TEST_RUNNER = 'django.test.runner.DiscoverRunner' +# For Celery Tests +app = celery.Celery() +app.config_from_object('django.conf:settings', namespace='CELERY') +app.autodiscover_tasks(lambda: INSTALLED_APPS) +BROKER_BACKEND = 'memory' +CELERY_TASK_ALWAYS_EAGER = True + +# kombu.exceptions.EncodeError: Object of type User is not JSON serializable エラーを抑止する +# (参考) +# https://github.com/celery/celery/issues/5922 +# https://stackoverflow.com/questions/49373825/kombu-exceptions-encodeerror-user-is-not-json-serializable +CELERY_TASK_SERIALIZER = "pickle" diff --git a/tests.py b/tests.py deleted file mode 100644 index 8945737..0000000 --- a/tests.py +++ /dev/null @@ -1,46 +0,0 @@ -import os -import sys -import django -import celery - -import test_settings - -BASE_PATH = os.path.dirname(__file__) - - -def main(): - """ - 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/ - """ - - # Django標準のdjango.conf.global_settingsを設定してしまうと、 - # Django3では、global_settingsの全ての定数を上書きする挙動になってしまい、 - # Django3の仕様で、多重上書き禁止エラーが検知され、例外が発生する。 - # (例) https://github.com/django/django/blob/70035fb0444ae7c01613374212ca5e3c27c9782c/django/conf/__init__.py#L188 - # そのため、自前のテスト用settingsモジュール(test_settings.py)を設定する。 - os.environ["DJANGO_SETTINGS_MODULE"] = "test_settings" - - app = celery.Celery() - app.config_from_object('django.conf:settings', namespace='CELERY') - app.autodiscover_tasks(lambda: test_settings.INSTALLED_APPS) - - django.setup() - - from django.test.utils import get_runner - - # test用のsettings情報を用いて、Djangoのtest runnerクラスを取得 - TestRunner = get_runner(test_settings) - - # test runnerオブジェクトを生成 - test_runner = TestRunner() - - # test runnerにbpnotifyの単体テストのPathを渡して、bpnotifyの単体テストを実行する - failures = test_runner.run_tests(['beproud.django.notify.tests']) - - sys.exit(failures) - - -if __name__ == '__main__': - main() diff --git a/tox.ini b/tox.ini index 3891b34..90d3805 100644 --- a/tox.ini +++ b/tox.ini @@ -1,8 +1,13 @@ # content of: tox.ini , put in same dir as setup.py [tox] -envlist = py{39,310,311}-dj{32,42}-celery{52,53},py312-dj42-celery53 +envlist = py{39,310,311,312}-dj42-celery53 skipsdist = True +[pytest] +python_files = tests test_*.py *_tests.py +django_find_project = false +DJANGO_SETTINGS_MODULE = test_settings + [testenv] basepython = py39: python3.9 @@ -15,11 +20,9 @@ deps = pytest-pythonpath setuptools six - dj32: Django>=3.2,<4.0 dj42: Django>=4.2,<5.0 - celery52: celery>=5.2,<5.3 celery53: celery>=5.3,<5.4 -commands=python setup.py test +commands=pytest {posargs} # tox-gh-actionsパッケージの設定 [gh-actions]