Skip to content

Create .editorconfig #1225

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

Merged
merged 21 commits into from
Aug 12, 2025
Merged
Show file tree
Hide file tree
Changes from 19 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
37 changes: 37 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions .editorconfig-checker.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Exclude": ["pytest_django/fixtures.py"],
"Disable": {
"MaxLineLength": true
}
}
10 changes: 10 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ env:
permissions: {}

jobs:
editorconfig:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- uses: editorconfig-checker/action-editorconfig-checker@0ab3427a3f09b17c21d489172245be511e0a16ea # v2
- run: editorconfig-checker

test:
runs-on: ubuntu-24.04
continue-on-error: ${{ matrix.allow_failure }}
Expand Down Expand Up @@ -156,6 +165,7 @@ jobs:

needs:
- test
- editorconfig

runs-on: ubuntu-24.04

Expand Down
10 changes: 5 additions & 5 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ build:
python: "3"

python:
install:
- method: pip
path: .
extra_requirements:
- docs
install:
- method: pip
path: .
extra_requirements:
- docs

formats:
- epub
Expand Down
2 changes: 1 addition & 1 deletion docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/managing_python_path.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ You can switch it on in `pytest.ini`::

[pytest]
FAIL_INVALID_TEMPLATE_VARS = True

Additional pytest.ini settings
------------------------------

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
18 changes: 9 additions & 9 deletions tests/test_django_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
115 changes: 72 additions & 43 deletions tests/test_django_settings_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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',
)
"""
)

Expand Down Expand Up @@ -195,19 +197,25 @@ def test_django_settings_configure(
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")

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()
"""
)

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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',
]
)
"""
)

Expand All @@ -336,22 +358,29 @@ 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(
"""
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)
)
Expand Down
20 changes: 11 additions & 9 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,10 +402,12 @@ def receiver(sender, **kwargs):
'<<does not exist>>')}
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)

Expand All @@ -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")
Expand Down Expand Up @@ -785,8 +787,7 @@ def django_mail_dnsname():
return 'from.django_mail_dnsname'

def test_mailbox_inner(mailoutbox):
mail.send_mail('subject', 'body', '[email protected]',
['[email protected]'])
mail.send_mail('subject', 'body', '[email protected]', ['[email protected]'])
m = mailoutbox[0]
message = m.message()
assert message['Message-ID'].endswith('@from.django_mail_dnsname>')
Expand Down Expand Up @@ -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', '[email protected]',
['[email protected]'])
mail.send_mail(
'subject', 'body', '[email protected]', ['[email protected]']
)
m = mailoutbox[0]
assert len(mocked_make_msgid.called) == 1

Expand Down
Loading