Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

テスト実行をpytestに移行 #17

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
python-version: ['3.9', '3.10', '3.11', '3.12']
django-version: ['3.2', '4.2']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

django-version: ['4.2']

steps:
# ソースコードをチェックアウト
Expand Down
8 changes: 8 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

おっと日付がXXのままだw

===================

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Comment on lines +11 to +12
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

もう使わなくなったのは削除した。

* six

Links
Expand Down
7 changes: 0 additions & 7 deletions beproud/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +0,0 @@
# See http://peak.telecommunity.com/DevCenter/setuptools#namespace-packages
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

以下のように非推奨であるメッセージがでるので [beproud/django/__init__.py](https://github.com/beproud/bpnotify/pull/17/files#diff-b84fb5fc7ef473b9cb42b0a428ef8da21bc7978986580b82b657b8cbb288498d) と合わせて削除

.tox/py311-dj42-celery53/lib/python3.11/site-packages/pkg_resources/__init__.py:121
  /Users/kashew/projects/github.com/beproud/bpnotify/.tox/py311-dj42-celery53/lib/python3.11/site-packages/pkg_resources/__init__.py:121: DeprecationWarning: pkg_resources is deprecated as an API
    warnings.warn("pkg_resources is deprecated as an API", DeprecationWarning)

beproud/__init__.py:3
  /Users/kashew/projects/github.com/beproud/bpnotify/beproud/__init__.py:3: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('beproud')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    __import__('pkg_resources').declare_namespace(__name__)

beproud/django/__init__.py:3
  /Users/kashew/projects/github.com/beproud/bpnotify/beproud/django/__init__.py:3: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('beproud.django')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    __import__('pkg_resources').declare_namespace(__name__)

.tox/py311-dj42-celery53/lib/python3.11/site-packages/pkg_resources/__init__.py:2349
  /Users/kashew/projects/github.com/beproud/bpnotify/.tox/py311-dj42-celery53/lib/python3.11/site-packages/pkg_resources/__init__.py:2349: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('beproud')`.
  Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    declare_namespace(parent)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

知らない人のために一応参考記事を貼っておきますね
Python 3.3b1 の名前空間パッケージを試してみた — 清水川Web

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__)
7 changes: 0 additions & 7 deletions beproud/django/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "bpnotify"
version = "0.49"
version = "0.50"
authors = [
{ name="BeProud Inc.", email="[email protected]" },
]
Expand All @@ -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"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(six.. まだいたのか)


[project.urls]
Homepage = "https://github.com/beproud/bpnotify/"
Expand Down
3 changes: 0 additions & 3 deletions setup.py

This file was deleted.

27 changes: 16 additions & 11 deletions test_settings.py
Original file line number Diff line number Diff line change
@@ -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定数を使用する。
Expand All @@ -9,20 +12,13 @@
'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',
'NAME': ':memory:',
}
}

import os
BASE_PATH = os.path.dirname(__file__)

TEMPLATES = [
Expand All @@ -33,8 +29,7 @@
],
},
]

CELERY_TASK_ALWAYS_EAGER = True
USE_TZ = False # For Django 5.0+
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MEMO: Django5.0で値が変更されるので明示的に設定

RemovedInDjango50Warning: The default value of USE_TZ will change from False to True in Django 5.0. Set USE_TZ to False in your project settings if you want to keep the current default behavior.
    warnings.warn(

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html


BPNOTIFY_MEDIA = {
"news": {
Expand All @@ -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)
Comment on lines +53 to +56
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここだけ追加している。他はimport順&記述内容の整理


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"
46 changes: 0 additions & 46 deletions tests.py

This file was deleted.

11 changes: 7 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand Down