Skip to content

Commit 8dd6acf

Browse files
authored
Create .editorconfig (#1225)
1 parent dce4ef5 commit 8dd6acf

11 files changed

+146
-70
lines changed

.editorconfig

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# https://editorconfig.org/
2+
3+
root = true
4+
5+
[*]
6+
indent_style = space
7+
indent_size = 4
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true
10+
end_of_line = lf
11+
charset = utf-8
12+
13+
[*.py]
14+
max_line_length = 99
15+
16+
[*.yml]
17+
indent_size = 2
18+
19+
[*.ini]
20+
indent_size = 2
21+
22+
[*.json]
23+
indent_size = 2
24+
insert_final_newline = unset
25+
26+
[*.rst]
27+
indent_size = unset
28+
insert_final_newline = unset
29+
30+
[*.bat]
31+
indent_style = tab
32+
33+
[LICENSE]
34+
indent_size = unset
35+
36+
[docs/Makefile]
37+
indent_style = tab

.editorconfig-checker.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"Exclude": ["pytest_django/fixtures.py"],
3+
"Disable": {
4+
"MaxLineLength": true
5+
}
6+
}

.readthedocs.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ build:
99
python: "3"
1010

1111
python:
12-
install:
13-
- method: pip
14-
path: .
15-
extra_requirements:
16-
- docs
12+
install:
13+
- method: pip
14+
path: .
15+
extra_requirements:
16+
- docs
1717

1818
formats:
1919
- epub

docs/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ How can I use ``manage.py test`` with pytest-django?
7979
----------------------------------------------------
8080

8181
pytest-django is designed to work with the ``pytest`` command, but if you
82-
really need integration with ``manage.py test``, you can add this class path
82+
really need integration with ``manage.py test``, you can add this class path
8383
in your Django settings:
8484

8585
.. code-block:: python

docs/managing_python_path.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ You can explicitly add paths to the Python search path using pytest's
8787
Example: project with src layout
8888
````````````````````````````````
8989

90-
For a Django package using the ``src`` layout, with test settings located in a
90+
For a Django package using the ``src`` layout, with test settings located in a
9191
``tests`` package at the top level::
9292

9393
myproj

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ You can switch it on in `pytest.ini`::
3333

3434
[pytest]
3535
FAIL_INVALID_TEMPLATE_VARS = True
36-
36+
3737
Additional pytest.ini settings
3838
------------------------------
3939

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[build-system]
22
requires = [
3-
"setuptools>=61.0.0",
4-
"setuptools-scm[toml]>=5.0.0",
3+
"setuptools>=61.0.0",
4+
"setuptools-scm[toml]>=5.0.0",
55
]
66
build-backend = "setuptools.build_meta"
77

@@ -63,6 +63,7 @@ xdist = [
6363
"pytest-xdist",
6464
]
6565
linting = [
66+
"editorconfig-checker==3.2.1",
6667
"mypy==1.15.0",
6768
"ruff==0.9.5",
6869
"zizmor==1.9.0",

tests/test_django_configurations.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ def test_dc_env_overrides_ini(pytester: pytest.Pytester, monkeypatch: pytest.Mon
5858

5959
pytester.makeini(
6060
"""
61-
[pytest]
62-
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
63-
DJANGO_CONFIGURATION = DO_NOT_USE_ini
61+
[pytest]
62+
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
63+
DJANGO_CONFIGURATION = DO_NOT_USE_ini
6464
"""
6565
)
6666
pkg = pytester.mkpydir("tpkg")
@@ -91,9 +91,9 @@ def test_dc_ini(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -> N
9191

9292
pytester.makeini(
9393
"""
94-
[pytest]
95-
DJANGO_SETTINGS_MODULE = tpkg.settings_ini
96-
DJANGO_CONFIGURATION = MySettings
94+
[pytest]
95+
DJANGO_SETTINGS_MODULE = tpkg.settings_ini
96+
DJANGO_CONFIGURATION = MySettings
9797
"""
9898
)
9999
pkg = pytester.mkpydir("tpkg")
@@ -125,9 +125,9 @@ def test_dc_option(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -
125125

126126
pytester.makeini(
127127
"""
128-
[pytest]
129-
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
130-
DJANGO_CONFIGURATION = DO_NOT_USE_ini
128+
[pytest]
129+
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
130+
DJANGO_CONFIGURATION = DO_NOT_USE_ini
131131
"""
132132
)
133133
pkg = pytester.mkpydir("tpkg")

tests/test_django_settings_module.py

Lines changed: 71 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_ds_ini(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -> N
2222
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")
2323
pytester.makeini(
2424
"""
25-
[pytest]
26-
DJANGO_SETTINGS_MODULE = tpkg.settings_ini
25+
[pytest]
26+
DJANGO_SETTINGS_MODULE = tpkg.settings_ini
2727
"""
2828
)
2929
pkg = pytester.mkpydir("tpkg")
@@ -72,8 +72,8 @@ def test_ds_option(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyPatch) -
7272
monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "DO_NOT_USE_env")
7373
pytester.makeini(
7474
"""
75-
[pytest]
76-
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
75+
[pytest]
76+
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
7777
"""
7878
)
7979
pkg = pytester.mkpydir("tpkg")
@@ -101,8 +101,8 @@ def test_ds_env_override_ini(pytester: pytest.Pytester, monkeypatch: pytest.Monk
101101
monkeypatch.setenv("DJANGO_SETTINGS_MODULE", "tpkg.settings_env")
102102
pytester.makeini(
103103
"""\
104-
[pytest]
105-
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
104+
[pytest]
105+
DJANGO_SETTINGS_MODULE = DO_NOT_USE_ini
106106
"""
107107
)
108108
pkg = pytester.mkpydir("tpkg")
@@ -166,8 +166,10 @@ def test_ds_in_pytest_configure(
166166
167167
def pytest_configure():
168168
if not settings.configured:
169-
os.environ.setdefault('DJANGO_SETTINGS_MODULE',
170-
'tpkg.settings_ds')
169+
os.environ.setdefault(
170+
'DJANGO_SETTINGS_MODULE',
171+
'tpkg.settings_ds',
172+
)
171173
"""
172174
)
173175

@@ -196,18 +198,24 @@ def test_django_settings_configure(
196198

197199
p = pytester.makepyfile(
198200
run="""
199-
from django.conf import settings
200-
settings.configure(SECRET_KEY='set from settings.configure()',
201-
DATABASES={'default': {
202-
'ENGINE': 'django.db.backends.sqlite3',
203-
'NAME': ':memory:'
204-
}},
205-
INSTALLED_APPS=['django.contrib.auth',
206-
'django.contrib.contenttypes',])
207-
208-
import pytest
209-
210-
pytest.main()
201+
from django.conf import settings
202+
settings.configure(
203+
SECRET_KEY='set from settings.configure()',
204+
DATABASES={
205+
'default': {
206+
'ENGINE': 'django.db.backends.sqlite3',
207+
'NAME': ':memory:'
208+
}
209+
},
210+
INSTALLED_APPS=[
211+
'django.contrib.auth',
212+
'django.contrib.contenttypes',
213+
]
214+
)
215+
216+
import pytest
217+
218+
pytest.main()
211219
"""
212220
)
213221

@@ -249,12 +257,19 @@ def test_settings_in_hook(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyP
249257
from django.conf import settings
250258
251259
def pytest_configure():
252-
settings.configure(SECRET_KEY='set from pytest_configure',
253-
DATABASES={'default': {
254-
'ENGINE': 'django.db.backends.sqlite3',
255-
'NAME': ':memory:'}},
256-
INSTALLED_APPS=['django.contrib.auth',
257-
'django.contrib.contenttypes',])
260+
settings.configure(
261+
SECRET_KEY='set from pytest_configure',
262+
DATABASES={
263+
'default': {
264+
'ENGINE': 'django.db.backends.sqlite3',
265+
'NAME': ':memory:'
266+
}
267+
},
268+
INSTALLED_APPS=[
269+
'django.contrib.auth',
270+
'django.contrib.contenttypes',
271+
]
272+
)
258273
"""
259274
)
260275
pytester.makepyfile(
@@ -305,13 +320,20 @@ def test_debug_false_by_default(
305320
from django.conf import settings
306321
307322
def pytest_configure():
308-
settings.configure(SECRET_KEY='set from pytest_configure',
309-
DEBUG=True,
310-
DATABASES={'default': {
311-
'ENGINE': 'django.db.backends.sqlite3',
312-
'NAME': ':memory:'}},
313-
INSTALLED_APPS=['django.contrib.auth',
314-
'django.contrib.contenttypes',])
323+
settings.configure(
324+
SECRET_KEY='set from pytest_configure',
325+
DEBUG=True,
326+
DATABASES={
327+
'default': {
328+
'ENGINE': 'django.db.backends.sqlite3',
329+
'NAME': ':memory:'
330+
}
331+
},
332+
INSTALLED_APPS=[
333+
'django.contrib.auth',
334+
'django.contrib.contenttypes',
335+
]
336+
)
315337
"""
316338
)
317339

@@ -336,22 +358,29 @@ def test_django_debug_mode_true_false(
336358
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")
337359
pytester.makeini(
338360
f"""
339-
[pytest]
340-
django_debug_mode = {django_debug_mode}
361+
[pytest]
362+
django_debug_mode = {django_debug_mode}
341363
"""
342364
)
343365
pytester.makeconftest(
344366
"""
345367
from django.conf import settings
346368
347369
def pytest_configure():
348-
settings.configure(SECRET_KEY='set from pytest_configure',
349-
DEBUG=%s,
350-
DATABASES={'default': {
351-
'ENGINE': 'django.db.backends.sqlite3',
352-
'NAME': ':memory:'}},
353-
INSTALLED_APPS=['django.contrib.auth',
354-
'django.contrib.contenttypes',])
370+
settings.configure(
371+
SECRET_KEY='set from pytest_configure',
372+
DEBUG=%s,
373+
DATABASES={
374+
'default': {
375+
'ENGINE': 'django.db.backends.sqlite3',
376+
'NAME': ':memory:'
377+
}
378+
},
379+
INSTALLED_APPS=[
380+
'django.contrib.auth',
381+
'django.contrib.contenttypes',
382+
]
383+
)
355384
"""
356385
% (not django_debug_mode)
357386
)

tests/test_fixtures.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,12 @@ def receiver(sender, **kwargs):
402402
'<<does not exist>>')}
403403
fmt_dict.update(kwargs)
404404
405-
print('Setting changed: '
406-
'enter=%(enter)s,setting=%(setting)s,'
407-
'value=%(value)s,actual_value=%(actual_value)s'
408-
% fmt_dict)
405+
print(
406+
'Setting changed: '
407+
'enter=%(enter)s,setting=%(setting)s,'
408+
'value=%(value)s,actual_value=%(actual_value)s'
409+
% fmt_dict
410+
)
409411
410412
setting_changed.connect(receiver, weak=False)
411413
@@ -417,7 +419,7 @@ def test_set(settings):
417419
418420
def test_set_non_existent(settings):
419421
settings.FOOBAR = 'abc123'
420-
"""
422+
"""
421423
)
422424

423425
result = django_pytester.runpytest_subprocess("--tb=short", "-v", "-s")
@@ -785,8 +787,7 @@ def django_mail_dnsname():
785787
return 'from.django_mail_dnsname'
786788
787789
def test_mailbox_inner(mailoutbox):
788-
mail.send_mail('subject', 'body', '[email protected]',
789-
790+
mail.send_mail('subject', 'body', '[email protected]', ['[email protected]'])
790791
m = mailoutbox[0]
791792
message = m.message()
792793
assert message['Message-ID'].endswith('@from.django_mail_dnsname>')
@@ -817,8 +818,9 @@ def mocked_make_msgid(*args, **kwargs):
817818
mocked_make_msgid.called = []
818819
819820
monkeypatch.setattr(mail.message, 'make_msgid', mocked_make_msgid)
820-
mail.send_mail('subject', 'body', '[email protected]',
821-
821+
mail.send_mail(
822+
'subject', 'body', '[email protected]', ['[email protected]']
823+
)
822824
m = mailoutbox[0]
823825
assert len(mocked_make_msgid.called) == 1
824826

0 commit comments

Comments
 (0)