You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have been profiling the unit test part of a flask project lately. My issue is that launching a single unit test takes ~4s on a very capable computer. This is not acceptable to me as I do test driven development, each second is multiplied by dozen and dozen runs each day, and this gives me a frustrating sensation. My investigations lead me to look around import times.
I have been profiling my tests with the unfamous importtime python option with something like: python -X importtime -c "import web; web.create_app()".
By deferring some library calls from the conftest.py files root to the inside of my pytest fixtures, I could save some precious seconds. Now the bottleneck has moved, and it seems some of latency is due to wtforms, and among others this import and the ones behind it:
In addition to that, the wtforms descriptor-like behavior implies that the fields are instantiated at import time the if a form class is defined at the module level. In addition to that, validators objects must be instantiated to be passed to fields:
I have been profiling the unit test part of a flask project lately. My issue is that launching a single unit test takes ~4s on a very capable computer. This is not acceptable to me as I do test driven development, each second is multiplied by dozen and dozen runs each day, and this gives me a frustrating sensation. My investigations lead me to look around import times.
I have been profiling my tests with the unfamous importtime python option with something like:
python -X importtime -c "import web; web.create_app()"
.By deferring some library calls from the
conftest.py
files root to the inside of my pytest fixtures, I could save some precious seconds. Now the bottleneck has moved, and it seems some of latency is due to wtforms, and among others this import and the ones behind it:https://github.com/wtforms/wtforms/blob/efe4e90acdb4a6b5d9b64a25756a33b41719319b/src/wtforms/validators.py#L6-L9
In addition to that, the wtforms descriptor-like behavior implies that the fields are instantiated at import time the if a form class is defined at the module level. In addition to that, validators objects must be instantiated to be passed to fields:
https://github.com/wtforms/wtforms/blob/efe4e90acdb4a6b5d9b64a25756a33b41719319b/src/wtforms/fields/core.py#L184-L188
So if a form class is defined at the module level, all the fields and all the objects validators are instantiated.
In order to slightly improve those performances I suggest to :
I would love to hear you on that @davidism
The text was updated successfully, but these errors were encountered: