Skip to content

Commit 5c851a7

Browse files
Improved code coverage
1 parent 5f9fa99 commit 5c851a7

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

tests/test_django_settings_module.py

+51
Original file line numberDiff line numberDiff line change
@@ -533,3 +533,54 @@ def test_ds():
533533
)
534534
result = testdir.runpytest_subprocess()
535535
assert result.ret == 0
536+
537+
538+
def test_dch_ini_no_module(testdir, monkeypatch) -> None:
539+
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")
540+
testdir.makeini(
541+
"""
542+
[pytest]
543+
DJANGO_CONFIGURATION_HOOK = tpkg.not_existing.setup
544+
"""
545+
)
546+
testdir.makepyfile(
547+
"""
548+
import os
549+
550+
def test_ds():
551+
pass
552+
"""
553+
)
554+
result = testdir.runpytest_subprocess()
555+
result.stderr.fnmatch_lines(["ImportError: Unable to import module tpkg.not_existing"])
556+
assert result.ret == 1
557+
558+
559+
def test_dch_ini_module_but_no_func(testdir, monkeypatch) -> None:
560+
monkeypatch.delenv("DJANGO_SETTINGS_MODULE")
561+
testdir.makeini(
562+
"""
563+
[pytest]
564+
DJANGO_CONFIGURATION_HOOK = tpkg.test.not_existing_function
565+
"""
566+
)
567+
pkg = testdir.mkpydir("tpkg")
568+
pkg.join("test.py").write("""
569+
# Test
570+
from django.conf import settings
571+
572+
def setup():
573+
settings.configure()
574+
""")
575+
testdir.makepyfile(
576+
"""
577+
import os
578+
579+
def test_ds():
580+
pass
581+
"""
582+
)
583+
result = testdir.runpytest_subprocess()
584+
result.stderr.fnmatch_lines(["ImportError: No function found with name "
585+
"not_existing_function in module tpkg.test!"])
586+
assert result.ret == 1

0 commit comments

Comments
 (0)