Skip to content

tests: skip modules whose optional extra is not installed - #1478

Merged
Rafiot merged 1 commit into
MISP:mainfrom
chiruu12:tests-skip-missing-extras
Aug 25, 2026
Merged

tests: skip modules whose optional extra is not installed#1478
Rafiot merged 1 commit into
MISP:mainfrom
chiruu12:tests-skip-missing-extras

Conversation

@chiruu12

Copy link
Copy Markdown
Contributor

Self-found while setting up to work on something else, so there is no issue to link.

The problem

pip install -e . without extras, then pytest tests/:

ImportError: cannot import name 'EMailObject' from 'pymisp.tools'
ERROR tests/test_emailobject.py
!!!! Interrupted: 1 error during collection !!!!
1 error in 0.14s

The run stops at collection, so no test executes at all. Two more modules fail once that is cleared: test_openioc.py raises Exception: You need to install BeautifulSoup from all its tests, and test_fileobject.py::test_mimeType fails with a bare StopIteration, because without libmagic the object carries no mimetype attribute and next() runs off the end.

CI installs every extra, so none of this shows up there. It only hits someone setting the project up.

The change

Each of the three modules skips when its extra is absent.

test_emailobject.py guards the EMailObject import and skips the class. test_openioc.py skips the class on openioc.has_bs4, which the module already imports. test_fileobject.py skips the one mimetype test on HAS_MAGIC. Both flags are the library's own, so nothing new is introduced to keep in sync.

test_openioc.py already wrapped its bs4 warning-filter import in try/except ImportError, so the file anticipated bs4 being missing and then failed anyway. This finishes that.

Before and after

Bare pip install -e . pytest, no extras:

main         1 error in 0.14s            (collection aborted, 0 tests run)
this branch  80 passed, 35 skipped

With every extra installed, matching CI:

main         89 passed, 25 skipped, 1 failed
this branch  89 passed, 26 skipped

The one moved test is test_mimeType, which skips here only because libmagic is absent on this machine. With the fileobjects extra working it runs as before.

mypy clean on all three files.

Scope

Tests only. No library code, no behaviour change, no new dependency.

Copilot AI lite review requested due to automatic review settings August 25, 2026 21:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@Rafiot
Rafiot merged commit e7debb4 into MISP:main Aug 25, 2026
8 checks passed
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.

3 participants