Skip to content

Commit 7bf7264

Browse files
authored
.
1 parent ed7a134 commit 7bf7264

File tree

6 files changed

+121
-88
lines changed

6 files changed

+121
-88
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,12 @@ indent_size = 2
1919
[*.ini]
2020
indent_size = 2
2121

22+
[*.json]
23+
indent_size = 2
24+
2225
[*.rst]
2326
indent_size = 4
27+
insert_final_newline = false
2428

2529
[*.bat]
2630
indent_style = tab

docs/helpers.rst

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -383,15 +383,15 @@ created in data migrations, you should add the
383383

384384
.. note:: Combining database access fixtures.
385385

386-
When using multiple database fixtures together, only one of them is
387-
used. Their order of precedence is as follows (the last one wins):
386+
When using multiple database fixtures together, only one of them is
387+
used. Their order of precedence is as follows (the last one wins):
388388

389-
* ``db``
390-
* ``transactional_db``
389+
* ``db``
390+
* ``transactional_db``
391391

392-
In addition, using ``live_server`` or ``django_db_reset_sequences`` will also
393-
trigger transactional database access, and ``django_db_serialized_rollback``
394-
regular database access, if not specified.
392+
In addition, using ``live_server`` or ``django_db_reset_sequences`` will also
393+
trigger transactional database access, and ``django_db_serialized_rollback``
394+
regular database access, if not specified.
395395

396396
.. fixture:: settings
397397

@@ -419,10 +419,10 @@ Example
419419

420420
.. py:function:: django_assert_num_queries(num, connection=None, info=None, *, using=None)
421421
422-
:param num: expected number of queries
423-
:param connection: optional database connection
424-
:param str info: optional info message to display on failure
425-
:param str using: optional database alias
422+
:param num: expected number of queries
423+
:param connection: optional database connection
424+
:param str info: optional info message to display on failure
425+
:param str using: optional database alias
426426

427427
This fixture allows to check for an expected number of DB queries.
428428

@@ -459,10 +459,10 @@ If you use type annotations, you can annotate the fixture like this::
459459

460460
.. py:function:: django_assert_max_num_queries(num, connection=None, info=None, *, using=None)
461461
462-
:param num: expected maximum number of queries
463-
:param connection: optional database connection
464-
:param str info: optional info message to display on failure
465-
:param str using: optional database alias
462+
:param num: expected maximum number of queries
463+
:param connection: optional database connection
464+
:param str info: optional info message to display on failure
465+
:param str using: optional database alias
466466

467467
This fixture allows to check for an expected maximum number of DB queries.
468468

@@ -492,12 +492,12 @@ If you use type annotations, you can annotate the fixture like this::
492492

493493
.. py:function:: django_capture_on_commit_callbacks(*, using=DEFAULT_DB_ALIAS, execute=False)
494494
495-
:param using:
496-
The alias of the database connection to capture callbacks for.
497-
:param execute:
498-
If True, all the callbacks will be called as the context manager exits, if
499-
no exception occurred. This emulates a commit after the wrapped block of
500-
code.
495+
:param using:
496+
The alias of the database connection to capture callbacks for.
497+
:param execute:
498+
If True, all the callbacks will be called as the context manager exits, if
499+
no exception occurred. This emulates a commit after the wrapped block of
500+
code.
501501

502502
.. versionadded:: 4.4
503503

docs/index.rst

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Quick Start
1313

1414
.. code-block:: bash
1515
16-
$ pip install pytest-django
16+
$ pip install pytest-django
1717
1818
Make sure ``DJANGO_SETTINGS_MODULE`` is defined (see
1919
:ref:`configuring_django_settings`) and make your tests discoverable
@@ -24,28 +24,28 @@ Example using pytest.ini or tox.ini
2424

2525
.. code-block:: ini
2626
27-
# -- FILE: pytest.ini (or tox.ini)
28-
[pytest]
29-
DJANGO_SETTINGS_MODULE = test.settings
30-
# -- recommended but optional:
31-
python_files = tests.py test_*.py *_tests.py
27+
# -- FILE: pytest.ini (or tox.ini)
28+
[pytest]
29+
DJANGO_SETTINGS_MODULE = test.settings
30+
# -- recommended but optional:
31+
python_files = tests.py test_*.py *_tests.py
3232
3333
Example using pyproject.toml
3434
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3535

3636
.. code-block:: toml
3737
38-
# -- Example FILE: pyproject.toml
39-
[tool.pytest.ini_options]
40-
DJANGO_SETTINGS_MODULE = "test.settings"
41-
# -- recommended but optional:
42-
python_files = ["test_*.py", "*_test.py", "testing/python/*.py"]
38+
# -- Example FILE: pyproject.toml
39+
[tool.pytest.ini_options]
40+
DJANGO_SETTINGS_MODULE = "test.settings"
41+
# -- recommended but optional:
42+
python_files = ["test_*.py", "*_test.py", "testing/python/*.py"]
4343
4444
Run your tests with ``pytest``:
4545

4646
.. code-block:: bash
4747
48-
$ pytest
48+
$ pytest
4949
5050
Why would I use this instead of Django's manage.py test command?
5151
================================================================
@@ -73,17 +73,17 @@ Table of Contents
7373
=================
7474

7575
.. toctree::
76-
:maxdepth: 3
77-
78-
tutorial
79-
configuring_django
80-
managing_python_path
81-
usage
82-
database
83-
helpers
84-
faq
85-
contributing
86-
changelog
76+
:maxdepth: 3
77+
78+
tutorial
79+
configuring_django
80+
managing_python_path
81+
usage
82+
database
83+
helpers
84+
faq
85+
contributing
86+
changelog
8787

8888
Indices and Tables
8989
==================

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

tests/test_django_settings_module.py

Lines changed: 62 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -197,19 +197,25 @@ def test_django_settings_configure(
197197
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")
198198

199199
p = pytester.makepyfile(
200-
run="""
201-
from django.conf import settings
202-
settings.configure(SECRET_KEY='set from settings.configure()',
203-
DATABASES={'default': {
204-
'ENGINE': 'django.db.backends.sqlite3',
205-
'NAME': ':memory:'
206-
}},
207-
INSTALLED_APPS=['django.contrib.auth',
208-
'django.contrib.contenttypes',])
209-
210-
import pytest
211-
212-
pytest.main()
200+
"""
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()
213219
"""
214220
)
215221

@@ -251,12 +257,19 @@ def test_settings_in_hook(pytester: pytest.Pytester, monkeypatch: pytest.MonkeyP
251257
from django.conf import settings
252258
253259
def pytest_configure():
254-
settings.configure(SECRET_KEY='set from pytest_configure',
255-
DATABASES={'default': {
256-
'ENGINE': 'django.db.backends.sqlite3',
257-
'NAME': ':memory:'}},
258-
INSTALLED_APPS=['django.contrib.auth',
259-
'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+
)
260273
"""
261274
)
262275
pytester.makepyfile(
@@ -307,13 +320,20 @@ def test_debug_false_by_default(
307320
from django.conf import settings
308321
309322
def pytest_configure():
310-
settings.configure(SECRET_KEY='set from pytest_configure',
311-
DEBUG=True,
312-
DATABASES={'default': {
313-
'ENGINE': 'django.db.backends.sqlite3',
314-
'NAME': ':memory:'}},
315-
INSTALLED_APPS=['django.contrib.auth',
316-
'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+
)
317337
"""
318338
)
319339

@@ -338,22 +358,29 @@ def test_django_debug_mode_true_false(
338358
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")
339359
pytester.makeini(
340360
f"""
341-
[pytest]
342-
django_debug_mode = {django_debug_mode}
361+
[pytest]
362+
django_debug_mode = {django_debug_mode}
343363
"""
344364
)
345365
pytester.makeconftest(
346366
"""
347367
from django.conf import settings
348368
349369
def pytest_configure():
350-
settings.configure(SECRET_KEY='set from pytest_configure',
351-
DEBUG=%s,
352-
DATABASES={'default': {
353-
'ENGINE': 'django.db.backends.sqlite3',
354-
'NAME': ':memory:'}},
355-
INSTALLED_APPS=['django.contrib.auth',
356-
'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+
)
357384
"""
358385
% (not django_debug_mode)
359386
)

tests/test_fixtures.py

Lines changed: 10 additions & 8 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
@@ -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)