@@ -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 )
0 commit comments