Skip to content

Commit 9e6fc65

Browse files
Attempt to speed up project tests runtime
1 parent 74b2e29 commit 9e6fc65

File tree

8 files changed

+484
-414
lines changed

8 files changed

+484
-414
lines changed

tests/django_expanded_test_cases/tests/test_base_case/test_base_auth.py

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

tests/django_expanded_test_cases/tests/test_base_case/test_base_case.py

Lines changed: 12 additions & 399 deletions
Large diffs are not rendered by default.

tests/django_expanded_test_cases/tests/test_integration_case/test_integration_assertions.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ class IntegrationAssertionTestCase:
3131
It needs to be imported into other classes to execute.
3232
"""
3333

34+
@classmethod
35+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
36+
def setUpTestData(cls, *args, **kwargs):
37+
"""Override setting for faster tests."""
38+
super().setUpTestData(*args, **kwargs)
39+
40+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
41+
def setUp(self, *args, **kwargs):
42+
"""Override setting for faster tests."""
43+
super().setUp(*args, **kwargs)
44+
3445
# region Response Assertion Tests
3546

3647
def test__assertResponse__url(self):

tests/django_expanded_test_cases/tests/test_integration_case/test_integration_debug_json_output.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
class TestIntegrationDebugJsonOutput(IntegrationTestCase, IntegrationDebugOutputTestCase):
3131
"""Tests for IntegrationTestCase class "debug output" logic when handling JSON."""
3232

33+
@classmethod
34+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
35+
def setUpTestData(cls, *args, **kwargs):
36+
"""Override setting for faster tests."""
37+
super().setUpTestData(*args, **kwargs)
38+
39+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
40+
def setUp(self, *args, **kwargs):
41+
"""Override setting for faster tests."""
42+
super().setUp(*args, **kwargs)
43+
3344
# region Dict as Base
3445

3546
@unittest.mock.patch('sys.stdout', new_callable=io.StringIO)

tests/django_expanded_test_cases/tests/test_integration_case/test_integration_debug_output.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
# System Imports.
66
import io
7-
import logging
87
import unittest.mock
98
from unittest.mock import patch
109

@@ -60,6 +59,17 @@
6059

6160
class IntegrationDebugOutputTestCase:
6261

62+
@classmethod
63+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
64+
def setUpTestData(cls, *args, **kwargs):
65+
"""Override setting for faster tests."""
66+
super().setUpTestData(*args, **kwargs)
67+
68+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
69+
def setUp(self, *args, **kwargs):
70+
"""Override setting for faster tests."""
71+
super().setUp(*args, **kwargs)
72+
6373
def strip_text_colors(self, text):
6474
"""Strip out all potential color values, for easier testing."""
6575

tests/django_expanded_test_cases/tests/test_integration_case/test_integration_helpers.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
# System Imports.
66
import logging
7+
from unittest.mock import patch
78

89
# Third-Party Imports.
910
from django.contrib.auth.models import AnonymousUser, Group, Permission
@@ -21,6 +22,17 @@ class IntegrationHelperTestCase:
2122
It needs to be imported into other classes to execute.
2223
"""
2324

25+
@classmethod
26+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
27+
def setUpTestData(cls, *args, **kwargs):
28+
"""Override setting for faster tests."""
29+
super().setUpTestData(*args, **kwargs)
30+
31+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
32+
def setUp(self, *args, **kwargs):
33+
"""Override setting for faster tests."""
34+
super().setUp(*args, **kwargs)
35+
2436
def test___get_login_user__verify_login(self):
2537
""""""
2638
with self.subTest('Auto login as test user'):

tests/django_expanded_test_cases/tests/test_integration_case/test_integration_hooks.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,34 @@
33
"""
44

55
# System Imports.
6-
import logging
76
from unittest.mock import patch
87

98
# Third-Party Imports.
10-
from django.contrib.auth import get_user_model
119
from django.contrib.auth.models import AnonymousUser
12-
from django.core.exceptions import ValidationError
1310
from pytest import warns
1411

1512
# Internal Imports.
16-
from .test_integration_assertions import IntegrationAssertionTestCase
17-
from .test_integration_helpers import IntegrationHelperTestCase
1813
from django_expanded_test_cases import IntegrationTestCase
1914

2015

2116
# region Verify Hook Function Access
2217

2318

24-
class TestIntegrationHooks__CanAccessPreBuiltinHook(IntegrationTestCase):
19+
class IntegrationHookTestCase(IntegrationTestCase):
20+
21+
@classmethod
22+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
23+
def setUpTestData(cls, *args, **kwargs):
24+
"""Override setting for faster tests."""
25+
super().setUpTestData(*args, **kwargs)
26+
27+
@patch('django_expanded_test_cases.mixins.core_mixin.ETC_AUTO_GENERATE_USERS_IN_SETUPTESTDATA', True)
28+
def setUp(self, *args, **kwargs):
29+
"""Override setting for faster tests."""
30+
super().setUp(*args, **kwargs)
31+
32+
33+
class TestIntegrationHooks__CanAccessPreBuiltinHook(IntegrationHookTestCase):
2534
"""Tests to ensure _assertResponse__pre_builtin_tests() hook function can be accessed.
2635
2736
Separate class to ensure other tests don't potentially affect state of class.
@@ -41,7 +50,7 @@ def test_hook_is_called(self):
4150
self.assertEqual(False, self.hook_checks.pre_assert_is_okay)
4251

4352

44-
class TestIntegrationHooks__CanAccessPostBuiltinHook(IntegrationTestCase):
53+
class TestIntegrationHooks__CanAccessPostBuiltinHook(IntegrationHookTestCase):
4554
"""Tests to ensure _assertResponse__post_builtin_tests() hook function can be accessed.
4655
4756
Separate class to ensure other tests don't potentially affect state of class.
@@ -61,7 +70,7 @@ def test_hook_is_called(self):
6170
self.assertEqual(False, self.hook_checks.post_assert_is_okay)
6271

6372

64-
class TestIntegrationHooks__CanAccessAuthSetupHook(IntegrationTestCase):
73+
class TestIntegrationHooks__CanAccessAuthSetupHook(IntegrationHookTestCase):
6574
"""Tests to ensure _get_login_user__extra_user_auth_setup() hook function can be accessed.
6675
6776
Separate class to ensure other tests don't potentially affect state of class.
@@ -93,7 +102,7 @@ def test_hook_is_called(self):
93102
# region Hook Warning Functionality
94103

95104

96-
class TestIntegrationHooks__HookRaisesWarning(IntegrationTestCase):
105+
class TestIntegrationHooks__HookRaisesWarning(IntegrationHookTestCase):
97106
"""Tests to ensure appropriate warnings raise with hook logic.
98107
99108
Separate class to ensure other tests don't potentially affect state of class.
@@ -151,7 +160,7 @@ def test_warning_raises_with_kwargs__with_real_user(self):
151160
self.assertText(self.expected_warn_msg, warning_msgs[0].message.args[0])
152161

153162

154-
class TestIntegrationHooks__PreBuiltinHookAffectsWarning(IntegrationTestCase):
163+
class TestIntegrationHooks__PreBuiltinHookAffectsWarning(IntegrationHookTestCase):
155164
"""Tests to ensure appropriate warnings are affected by implementation of
156165
_assertResponse__pre_builtin_tests() hook.
157166
@@ -205,7 +214,7 @@ def test_warning_does_not_raise_with_kwargs__with_real_user(self):
205214
)
206215

207216

208-
class TestIntegrationHooks__PostBuiltinHookAffectsWarning(IntegrationTestCase):
217+
class TestIntegrationHooks__PostBuiltinHookAffectsWarning(IntegrationHookTestCase):
209218
"""Tests to ensure appropriate warnings are affected by implementation of
210219
_assertResponse__post_builtin_tests() hook.
211220
@@ -259,7 +268,7 @@ def test_warning_does_not_raise_with_kwargs__with_real_user(self):
259268
)
260269

261270

262-
class TestIntegrationHooks__CanAccessAuthSetupHookAffectsWarning(IntegrationTestCase):
271+
class TestIntegrationHooks__CanAccessAuthSetupHookAffectsWarning(IntegrationHookTestCase):
263272
"""Tests to ensure appropriate warnings are affected by implementation of
264273
_get_login_user__extra_user_auth_setup() hook.
265274

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ description = Main testing logic for most python/django combinations.
2727
allowlist_externals = django-admin
2828
commands =
2929
django-admin --version
30-
python ./runtests.py --show-return-code --cov=. --ignore=.tox --disable-pytest-warnings --cov-report=lcov --cov-append {toxinidir}
30+
python ./runtests.py -n auto --show-return-code --cov=. --ignore=.tox --disable-pytest-warnings --cov-report=lcov --cov-append {toxinidir}
3131
setenv = PYTHONDONTWRITEBYTECODE=1
3232
deps =
3333
django22: Django>=2.2,<3.0
@@ -54,7 +54,7 @@ commands = sphinx-build -E docs/source docs/build
5454
description = Check for raised warnings on bleeding edge of project.
5555
ignore_outcome = True
5656
unignore_outcomes = True
57-
commands = python ./runtests.py --show-return-code -W error {posargs}
57+
commands = python ./runtests.py -n auto --show-return-code -W error {posargs}
5858
deps =
5959
{[latest]deps}
6060

0 commit comments

Comments
 (0)