4
4
import pytest
5
5
from pprint import pformat
6
6
from .utils import rich_installed
7
+ import platform
7
8
8
9
9
10
@pytest .mark .no_rich
@@ -27,13 +28,13 @@ def test_performance_regression():
27
28
result , stderr , retcode = run_command (
28
29
"perf" ,
29
30
"5" ,
30
- "--test-option " ,
31
+ "--print " ,
31
32
env = {** env , "DJANGO_SETTINGS_MODULE" : "tests.settings.perf_no_typer" },
32
33
)
33
34
end = time .perf_counter ()
34
35
if retcode :
35
36
pytest .fail (stderr )
36
- assert result ["test_option " ]
37
+ assert result ["print " ]
37
38
assert result ["no_typer" ] == 5
38
39
mods_no_typer = result ["modules" ]
39
40
no_typer_time = end - start
@@ -42,13 +43,13 @@ def test_performance_regression():
42
43
result , stderr , retcode = run_command (
43
44
"perf" ,
44
45
"5" ,
45
- "--test-option " ,
46
+ "--print " ,
46
47
env = {** env , "DJANGO_SETTINGS_MODULE" : "tests.settings.perf_typer" },
47
48
)
48
49
end = time .perf_counter ()
49
50
if retcode :
50
51
pytest .fail (stderr )
51
- assert result ["test_option " ]
52
+ assert result ["print " ]
52
53
assert result ["typer" ] == 5
53
54
mods_typer = result ["modules" ]
54
55
typer_time = end - start
@@ -57,13 +58,13 @@ def test_performance_regression():
57
58
result , stderr , retcode = run_command (
58
59
"perf" ,
59
60
"5" ,
60
- "--test-option " ,
61
+ "--print " ,
61
62
env = {** env , "DJANGO_SETTINGS_MODULE" : "tests.settings.perf_typer_no_app" },
62
63
)
63
64
end = time .perf_counter ()
64
65
if retcode :
65
66
pytest .fail (stderr )
66
- assert result ["test_option " ]
67
+ assert result ["print " ]
67
68
assert result ["typer" ] == 5
68
69
mods_typer_no_app = result ["modules" ]
69
70
typer_no_app_time = end - start
@@ -89,6 +90,68 @@ def test_performance_regression():
89
90
f"Typer modules added: \n { pformat (set (mods_typer_no_app ) - set (mods_no_typer ))} "
90
91
)
91
92
92
- # notify us if adding typer inflates command exec time by more than 50 percent
93
- assert no_typer_time / typer_time > 0.5
94
- assert no_typer_time / typer_no_app_time > 0.5
93
+ # notify us if adding typer inflates command exec time by more than 20 percent
94
+ assert no_typer_time / typer_time > 0.2
95
+ assert no_typer_time / typer_no_app_time > 0.2
96
+
97
+
98
+ @pytest .mark .no_rich
99
+ @pytest .mark .skipif (
100
+ rich_installed , reason = "Rich should not be installed to test module bloat."
101
+ )
102
+ @pytest .mark .skipif (platform .system () != "Darwin" , reason = "Test is only for macOS" )
103
+ def test_timing ():
104
+ env = dict (os .environ )
105
+ # disable coverage
106
+ for var in [
107
+ "COVERAGE_PROCESS_START" ,
108
+ "COV_CORE_SOURCE" ,
109
+ "COV_CORE_CONFIG" ,
110
+ "COV_CORE_DATAFILE" ,
111
+ "PYTEST_XDIST_WORKER" ,
112
+ ]:
113
+ env .pop (var , None )
114
+
115
+ result , stderr , retcode , no_typer_seconds = run_command (
116
+ "perf" ,
117
+ "5" ,
118
+ env = {** env , "DJANGO_SETTINGS_MODULE" : "tests.settings.perf_no_typer" },
119
+ time = True ,
120
+ )
121
+ if retcode :
122
+ pytest .fail (stderr )
123
+ assert not result , "perf should not have printed"
124
+
125
+ result , stderr , retcode , typer_seconds = run_command (
126
+ "perf" ,
127
+ "5" ,
128
+ env = {** env , "DJANGO_SETTINGS_MODULE" : "tests.settings.perf_typer" },
129
+ time = True ,
130
+ )
131
+ if retcode :
132
+ pytest .fail (stderr )
133
+ assert not result , "perf should not have printed"
134
+
135
+ result , stderr , retcode , typer_no_app_seconds = run_command (
136
+ "perf" ,
137
+ "5" ,
138
+ env = {** env , "DJANGO_SETTINGS_MODULE" : "tests.settings.perf_typer_no_app" },
139
+ time = True ,
140
+ )
141
+ if retcode :
142
+ pytest .fail (stderr )
143
+ assert not result , "perf should not have printed"
144
+
145
+ # print the stats
146
+ print ("\n Without typer:\n \t " )
147
+ print (f"\t time: { no_typer_seconds :0.4f} " )
148
+
149
+ print ("\n With typer:\n \t " )
150
+ print (f"\t time: { typer_seconds :0.4f} " )
151
+
152
+ print ("\n With typer, but app not installed:\n \t " )
153
+ print (f"\t time: { typer_no_app_seconds :0.4f} " )
154
+
155
+ # notify us if adding typer inflates command exec time by more than 20 percent
156
+ assert no_typer_seconds / typer_seconds > 0.2
157
+ assert no_typer_seconds / typer_no_app_seconds > 0.2
0 commit comments