diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..1e469181 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,37 @@ +# https://editorconfig.org/ + +root = true + +[*] +indent_style = space +indent_size = 4 +insert_final_newline = true +trim_trailing_whitespace = true +end_of_line = lf +charset = utf-8 + +[*.py] +max_line_length = 99 + +[*.yml] +indent_size = 2 + +[*.ini] +indent_size = 2 + +[*.json] +indent_size = 2 +insert_final_newline = unset + +[*.rst] +indent_size = unset +insert_final_newline = unset + +[*.bat] +indent_style = tab + +[LICENSE] +indent_size = unset + +[docs/Makefile] +indent_style = tab diff --git a/.editorconfig-checker.json b/.editorconfig-checker.json new file mode 100644 index 00000000..3fa0e744 --- /dev/null +++ b/.editorconfig-checker.json @@ -0,0 +1,6 @@ +{ + "Exclude": ["pytest_django/fixtures.py"], + "Disable": { + "MaxLineLength": true + } +} diff --git a/.readthedocs.yml b/.readthedocs.yml index ba6a262b..c13e1e00 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -9,11 +9,11 @@ build: python: "3" python: - install: - - method: pip - path: . - extra_requirements: - - docs + install: + - method: pip + path: . + extra_requirements: + - docs formats: - epub diff --git a/docs/faq.rst b/docs/faq.rst index 8ad588b0..5a4f4d88 100644 --- a/docs/faq.rst +++ b/docs/faq.rst @@ -79,7 +79,7 @@ How can I use ``manage.py test`` with pytest-django? ---------------------------------------------------- pytest-django is designed to work with the ``pytest`` command, but if you -really need integration with ``manage.py test``, you can add this class path +really need integration with ``manage.py test``, you can add this class path in your Django settings: .. code-block:: python diff --git a/docs/managing_python_path.rst b/docs/managing_python_path.rst index 37488662..561ef822 100644 --- a/docs/managing_python_path.rst +++ b/docs/managing_python_path.rst @@ -87,7 +87,7 @@ You can explicitly add paths to the Python search path using pytest's Example: project with src layout ```````````````````````````````` -For a Django package using the ``src`` layout, with test settings located in a +For a Django package using the ``src`` layout, with test settings located in a ``tests`` package at the top level:: myproj diff --git a/docs/usage.rst b/docs/usage.rst index edfead5e..6e9822c6 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -33,7 +33,7 @@ You can switch it on in `pytest.ini`:: [pytest] FAIL_INVALID_TEMPLATE_VARS = True - + Additional pytest.ini settings ------------------------------ diff --git a/pyproject.toml b/pyproject.toml index 36cdfe32..883143af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [build-system] requires = [ - "setuptools>=61.0.0", - "setuptools-scm[toml]>=5.0.0", + "setuptools>=61.0.0", + "setuptools-scm[toml]>=5.0.0", ] build-backend = "setuptools.build_meta" @@ -63,6 +63,7 @@ xdist = [ "pytest-xdist", ] linting = [ + "editorconfig-checker==3.2.1", "mypy==1.15.0", "ruff==0.9.5", "zizmor==1.9.0", diff --git a/tests/test_django_configurations.py b/tests/test_django_configurations.py index 88d89cf6..6e1a2b6d 100644 --- a/tests/test_django_configurations.py +++ b/tests/test_django_configurations.py @@ -58,9 +58,9 @@ def test_dc_env_overrides_ini(pytester: pytest.Pytester, monkeypatch: pytest.Mon pytester.makeini( """ - [pytest] - DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini - DJANGO_CONFIGURATION = DO_NOT_USE_ini + [pytest] + DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini + DJANGO_CONFIGURATION = DO_NOT_USE_ini """ ) pkg = pytester.mkpydir("tpkg") @@ -91,9 +91,9 @@ def test_dc_ini(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -> N pytester.makeini( """ - [pytest] - DJANGO_SETTINGS_MODULE = tpkg.settings_ini - DJANGO_CONFIGURATION = MySettings + [pytest] + DJANGO_SETTINGS_MODULE = tpkg.settings_ini + DJANGO_CONFIGURATION = MySettings """ ) pkg = pytester.mkpydir("tpkg") @@ -125,9 +125,9 @@ def test_dc_option(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) - pytester.makeini( """ - [pytest] - DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini - DJANGO_CONFIGURATION = DO_NOT_USE_ini + [pytest] + DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini + DJANGO_CONFIGURATION = DO_NOT_USE_ini """ ) pkg = pytester.mkpydir("tpkg") diff --git a/tests/test_django_settings_module.py b/tests/test_django_settings_module.py index fa4db778..68d587e9 100644 --- a/tests/test_django_settings_module.py +++ b/tests/test_django_settings_module.py @@ -22,8 +22,8 @@ def test_ds_ini(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -> N monkeypatch.delenv("DJANGO_SETTINGS_MODULE") pytester.makeini( """ - [pytest] - DJANGO_SETTINGS_MODULE = tpkg.settings_ini + [pytest] + DJANGO_SETTINGS_MODULE = tpkg.settings_ini """ ) pkg = pytester.mkpydir("tpkg") @@ -72,8 +72,8 @@ def test_ds_option(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) - monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "DO_NOT_USE_env") pytester.makeini( """ - [pytest] - DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini + [pytest] + DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini """ ) pkg = pytester.mkpydir("tpkg") @@ -101,8 +101,8 @@ def test_ds_env_override_ini(pytester: pytest.Pytester, monkeypatch: pytest.Monk monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "tpkg.settings_env") pytester.makeini( """\ - [pytest] - DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini + [pytest] + DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini """ ) pkg = pytester.mkpydir("tpkg") @@ -166,8 +166,10 @@ def test_ds_in_pytest_configure( def pytest_configure(): if not settings.configured: - os.environ.setdefault('DJANGO_SETTINGS_MODULE', - 'tpkg.settings_ds') + os.environ.setdefault( + 'DJANGO_SETTINGS_MODULE', + 'tpkg.settings_ds', + ) """ ) @@ -196,18 +198,24 @@ def test_django_settings_configure( p = pytester.makepyfile( run=""" - from django.conf import settings - settings.configure(SECRET_KEY='set from settings.configure()', - DATABASES={'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:' - }}, - INSTALLED_APPS=['django.contrib.auth', - 'django.contrib.contenttypes',]) - - import pytest - - pytest.main() + from django.conf import settings + settings.configure( + SECRET_KEY='set from settings.configure()', + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } + }, + INSTALLED_APPS=[ + 'django.contrib.auth', + 'django.contrib.contenttypes', + ] + ) + + import pytest + + pytest.main() """ ) @@ -249,12 +257,19 @@ def test_settings_in_hook(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyP from django.conf import settings def pytest_configure(): - settings.configure(SECRET_KEY='set from pytest_configure', - DATABASES={'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:'}}, - INSTALLED_APPS=['django.contrib.auth', - 'django.contrib.contenttypes',]) + settings.configure( + SECRET_KEY='set from pytest_configure', + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } + }, + INSTALLED_APPS=[ + 'django.contrib.auth', + 'django.contrib.contenttypes', + ] + ) """ ) pytester.makepyfile( @@ -305,13 +320,20 @@ def test_debug_false_by_default( from django.conf import settings def pytest_configure(): - settings.configure(SECRET_KEY='set from pytest_configure', - DEBUG=True, - DATABASES={'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:'}}, - INSTALLED_APPS=['django.contrib.auth', - 'django.contrib.contenttypes',]) + settings.configure( + SECRET_KEY='set from pytest_configure', + DEBUG=True, + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } + }, + INSTALLED_APPS=[ + 'django.contrib.auth', + 'django.contrib.contenttypes', + ] + ) """ ) @@ -336,8 +358,8 @@ def test_django_debug_mode_true_false( monkeypatch.delenv("DJANGO_SETTINGS_MODULE") pytester.makeini( f""" - [pytest] - django_debug_mode = {django_debug_mode} + [pytest] + django_debug_mode = {django_debug_mode} """ ) pytester.makeconftest( @@ -345,13 +367,20 @@ def test_django_debug_mode_true_false( from django.conf import settings def pytest_configure(): - settings.configure(SECRET_KEY='set from pytest_configure', - DEBUG=%s, - DATABASES={'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:'}}, - INSTALLED_APPS=['django.contrib.auth', - 'django.contrib.contenttypes',]) + settings.configure( + SECRET_KEY='set from pytest_configure', + DEBUG=%s, + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:' + } + }, + INSTALLED_APPS=[ + 'django.contrib.auth', + 'django.contrib.contenttypes', + ] + ) """ % (not django_debug_mode) ) diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py index 600ac626..80578959 100644 --- a/tests/test_fixtures.py +++ b/tests/test_fixtures.py @@ -402,10 +402,12 @@ def receiver(sender, **kwargs): '<>')} fmt_dict.update(kwargs) - print('Setting changed: ' - 'enter=%(enter)s,setting=%(setting)s,' - 'value=%(value)s,actual_value=%(actual_value)s' - % fmt_dict) + print( + 'Setting changed: ' + 'enter=%(enter)s,setting=%(setting)s,' + 'value=%(value)s,actual_value=%(actual_value)s' + % fmt_dict + ) setting_changed.connect(receiver, weak=False) @@ -417,7 +419,7 @@ def test_set(settings): def test_set_non_existent(settings): settings.FOOBAR = 'abc123' - """ + """ ) result = django_pytester.runpytest_subprocess("--tb=short", "-v", "-s") @@ -785,8 +787,7 @@ def django_mail_dnsname(): return 'from.django_mail_dnsname' def test_mailbox_inner(mailoutbox): - mail.send_mail('subject', 'body', 'from@example.com', - ['to@example.com']) + mail.send_mail('subject', 'body', 'from@example.com', ['to@example.com']) m = mailoutbox[0] message = m.message() assert message['Message-ID'].endswith('@from.django_mail_dnsname>') @@ -817,8 +818,9 @@ def mocked_make_msgid(*args, **kwargs): mocked_make_msgid.called = [] monkeypatch.setattr(mail.message, 'make_msgid', mocked_make_msgid) - mail.send_mail('subject', 'body', 'from@example.com', - ['to@example.com']) + mail.send_mail( + 'subject', 'body', 'from@example.com', ['to@example.com'] + ) m = mailoutbox[0] assert len(mocked_make_msgid.called) == 1 diff --git a/tox.ini b/tox.ini index 59d4cb57..a9c14a89 100644 --- a/tox.ini +++ b/tox.ini @@ -48,6 +48,7 @@ commands = ruff check --diff {posargs:pytest_django pytest_django_test tests} ruff format --quiet --diff {posargs:pytest_django pytest_django_test tests} mypy {posargs:pytest_django pytest_django_test tests} + ec {posargs:pytest_django pytest_django_test tests} python -c "import subprocess, sys; sys.exit(subprocess.call('zizmor --persona=pedantic --format sarif .github/workflows/deploy.yml .github/workflows/main.yml > zizmor.sarif', shell=True))" [testenv:doc8]