|
19 | 19 |
|
20 | 20 |
|
21 | 21 | @pytest.mark.django_project( |
22 | | - project_root="django_project_root", |
23 | 22 | extra_settings=""" |
24 | 23 | EMAIL_BACKEND = "django.core.mail.backends.dummy.EmailBackend" |
| 24 | + import unittest.mock |
| 25 | + from types import SimpleNamespace |
| 26 | +
|
| 27 | + def setup_test_environment(*a, **k): |
| 28 | + if hasattr(_TestState, "saved_data"): |
| 29 | + # Executing this function twice would overwrite the saved values. |
| 30 | + raise RuntimeError( |
| 31 | + "setup_test_environment() was already called and can't be called " |
| 32 | + "again without first calling teardown_test_environment()." |
| 33 | + ) |
| 34 | +
|
| 35 | + saved_data = SimpleNamespace() |
| 36 | + _TestState.saved_data = saved_data |
| 37 | + saved_data.allowed_hosts = [] |
| 38 | + saved_data.debug = False |
| 39 | + saved_data.email_backend = None |
| 40 | + saved_data.template_render = None |
| 41 | +
|
| 42 | + unittest.mock.patch("django.test.utils.setup_test_environment", setup_test_environment).start() |
| 43 | + from django.test.utils import _TestState |
25 | 44 | """, |
26 | 45 | ) |
27 | | -def test_manage_test_runner(django_pytester: DjangoPytester) -> None: |
| 46 | +def test_mail_auto_fixture(django_pytester: DjangoPytester) -> None: |
28 | 47 | django_pytester.create_test_module( |
29 | 48 | """ |
30 | 49 | def test_bad_mail(): |
31 | 50 | pass |
32 | 51 | """ |
33 | 52 | ) |
34 | | - result = django_pytester.runpytest_subprocess("-s") |
| 53 | + result = django_pytester.runpytest_subprocess("-s", "-vv") |
| 54 | + print("\n".join([*result.outlines, *result.errlines])) |
35 | 55 | assert "1 passed" in "\n".join([*result.outlines, *result.errlines]) |
36 | 56 |
|
37 | 57 |
|
|
0 commit comments