Skip to content

Commit

Permalink
pytest_plugin: disable flood protection for example tests
Browse files Browse the repository at this point in the history
For quite a while, we've had three tests from the `rand` plugin that
take several seconds each. I had a Sopelunk with the Git version [1] of
`pytest-profiling` [2] and discovered that about 98% of the time spent
on the five tests selected by `pytest -k rand.py` was in `time.sleep()`.

Drilling down, I saw that was being called from `bot.say()`, which led
pretty quickly to the real culprit: Flood protection.

There's no server to flood during tests, so we can just turn that
protection off. With this change, those five tests from `rand` went from
about 12 seconds on my test system down to about 0.25 sec.

[1]: The last actual release of `pytest-profiling` is from 2019, and it
     doesn't work on modern Python. (I started analyzing this under
     Python 3.13, while verifying fixes for new warnings there.) All of
     the necessary updates already exist in the Git repo, though; they
     just haven't published a new release in five years.

[2]: https://github.com/man-group/pytest-plugins/tree/master/pytest-profiling
  • Loading branch information
dgw committed Oct 9, 2024
1 parent 1c6aeb9 commit 17d46b7
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions sopel/tests/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
nick = {name}
owner = {owner}
admin = {admin}
# avoid wasting cycles in time.sleep() during `repeat`ed tests
flood_max_wait = 0
"""


Expand Down

0 comments on commit 17d46b7

Please sign in to comment.