Skip to content

Document how to make pytest-mpl optional #14

Description

@cdeil

One of the issues we struggled with for astroplan was how to make the image comparison tests optional, i.e. have them skipped if matplotlib or nose as optional dependencies aren't installed.

@astrofrog – What do you think about the solution @eteq came up with?
(see https://github.com/astropy/astroplan/blob/master/astroplan/conftest.py)

defpytest_configure(config):
ifhasattr(astropy_pytest_plugins, 'pytest_configure'):
# sure ought to be true right now, but always possible it will change in# future versions of astropyastropy_pytest_plugins.pytest_configure(config)
#make sure astroplan warnings always appear so we can test when they show upwarnings.simplefilter('always', category=AstroplanWarning)
try:
importmatplotlibimportnose# needed for the matplotlib testing toolsHAS_MATPLOTLIB_AND_NOSE=TrueexceptImportError:
HAS_MATPLOTLIB_AND_NOSE=FalseifHAS_MATPLOTLIB_AND_NOSEandconfig.pluginmanager.hasplugin('mpl'):
config.option.mpl=Trueconfig.option.mpl_baseline_path='astroplan/plots/tests/baseline_images'

@astrofrog – I'd like to set up image comparison tests for other packages in the near future and have them optional. Could you please document the recommended setup?

I think it would also be good to have a short list of "packages using pytest-mpl" ... there's nothing better than working examples to get started.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions