Skip to content

Add a pytest test suite and GitHub Actions CI - #10

Merged
cmaureir merged 1 commit into
mainfrom
tests/add-test-suite
Aug 12, 2026
Merged

Add a pytest test suite and GitHub Actions CI#10
cmaureir merged 1 commit into
mainfrom
tests/add-test-suite

Conversation

@cmaureir

Copy link
Copy Markdown
Member

Covers every comandos/*.py cog plus utils.py and configuration.py (103 tests), using lightweight fakes for discord.py objects instead of a full test harness like dpytest:

  • conftest.py (root): sandboxes a throwaway config.toml + logs/ dir and chdir()s into it before any comandos module is imported, since every such module instantiates the Config() singleton at import time and config.toml is git-ignored (real secrets).

  • tests/factories.py: fakes for members/roles/channels/messages/ attachments/bots. Uses MagicMock(spec=...) specifically where production code runs isinstance() checks (discord.Member, discord.TextChannel, discord.Interaction), plain objects elsewhere.

  • tests/conftest.py: fixtures wiring FloodSpam/Moderacion cogs the way on_ready() would, without needing a real discord.Client/Guild.

  • .github/workflows/tests.yml: runs the suite on push to main and on every pull request.

Along the way this surfaced a few pre-existing bugs, documented as tests/comments rather than fixed here (out of scope for "add tests"):

  • archivar.archivar_canal() returns (False, None) on a write failure; since a non-empty tuple is always truthy, archivar()'s if status: treats that as success (test_failure_tuple_is_still_truthy).

  • FloodSpam.on_message re-fetches the channel via bot.get_channel(message.channel.id) instead of using message.channel directly; a cache miss makes self._msg_channel None and crashes the first .send() call downstream.

  • Moderacion._aceptar_mensaje's jump_url is built from self._msg_id, a single field shared across all pending submissions, rather than the specific post being accepted (vp.post_id) - a second submission arriving before the first is moderated could produce a jump_url pointing at the wrong message.

Covers every comandos/*.py cog plus utils.py and configuration.py
(103 tests), using lightweight fakes for discord.py objects instead
of a full test harness like dpytest:

- conftest.py (root): sandboxes a throwaway config.toml + logs/ dir
  and chdir()s into it before any comandos module is imported, since
  every such module instantiates the Config() singleton at import
  time and config.toml is git-ignored (real secrets).

- tests/factories.py: fakes for members/roles/channels/messages/
  attachments/bots. Uses MagicMock(spec=...) specifically where
  production code runs isinstance() checks (discord.Member,
  discord.TextChannel, discord.Interaction), plain objects elsewhere.

- tests/conftest.py: fixtures wiring FloodSpam/Moderacion cogs the
  way on_ready() would, without needing a real discord.Client/Guild.

- .github/workflows/tests.yml: runs the suite on push to main and on
  every pull request.

Along the way this surfaced a few pre-existing bugs, documented as
tests/comments rather than fixed here (out of scope for "add tests"):

- archivar.archivar_canal() returns (False, None) on a write failure;
  since a non-empty tuple is always truthy, archivar()'s `if status:`
  treats that as success (test_failure_tuple_is_still_truthy).

- FloodSpam.on_message re-fetches the channel via
  bot.get_channel(message.channel.id) instead of using message.channel
  directly; a cache miss makes self._msg_channel None and crashes the
  first .send() call downstream.

- Moderacion._aceptar_mensaje's jump_url is built from self._msg_id, a
  single field shared across all pending submissions, rather than the
  specific post being accepted (vp.post_id) - a second submission
  arriving before the first is moderated could produce a jump_url
  pointing at the wrong message.
@cmaureir
cmaureir merged commit bcc6368 into main Aug 12, 2026
1 check passed
@cmaureir
cmaureir deleted the tests/add-test-suite branch August 12, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant