tests: skip modules whose optional extra is not installed - #1478
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Self-found while setting up to work on something else, so there is no issue to link.
The problem
pip install -e .without extras, thenpytest tests/:The run stops at collection, so no test executes at all. Two more modules fail once that is cleared:
test_openioc.pyraisesException: You need to install BeautifulSoupfrom all its tests, andtest_fileobject.py::test_mimeTypefails with a bareStopIteration, because without libmagic the object carries nomimetypeattribute andnext()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.pyguards theEMailObjectimport and skips the class.test_openioc.pyskips the class onopenioc.has_bs4, which the module already imports.test_fileobject.pyskips the one mimetype test onHAS_MAGIC. Both flags are the library's own, so nothing new is introduced to keep in sync.test_openioc.pyalready wrapped its bs4 warning-filter import intry/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:With every extra installed, matching CI:
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.mypyclean on all three files.Scope
Tests only. No library code, no behaviour change, no new dependency.