Package: pytest-remotedata
This package provides a plugin for thepytestframework that allows
developers to control unit tests that require access to data from the internet.
It was originally part of theastropycore package, but has been moved to a
separate package in order to be of more general use.MotivationMany software packages provide features that require access to data from the
internet. These features need to be tested, but unit tests that access the
internet can dominate the overall runtime of a test suite.Thepytest-remotedataplugin allows developers to indicate which unit tests
require access to the internet, and to control when and whether such tests
should execute as part of any given run of the test suite.InstallationThepytest-remotedataplugin can be installed usingpip:$ pip install pytest-remotedataIt is also possible to install the latest development version from the source
repository:$ git clone https://github.com/astropy/pytest-remotedata
$ cd pytest-remotedata
$ pip install .In either case, the plugin will automatically be registered for use withpytest.UsageInstalling this plugin makes two decorators available for use withpytest:remote_datafor marking tests that require data from the internetinternet_offfor marking tests that should run only when internet access
is disabledThese decorators can be used to mark test functions, methods, and classes using@pytest.mark. For example, consider the following test function that
requires access to data from the internet:importpytestfromurllib.requestimporturlopen@pytest.mark.remote_datadeftest_remote_data():urlopen('https://astropy.org')Marking thetest_remote_datafunction with@pytest.mark.remote_dataindicates topytestthat this test should be run only when access to remote
data sources is explicitly requested.When this plugin is installed, the--remote-datacommand line option is
added to thepytestcommand line interface.The default behavior is to skip tests that are marked withremote_data.
If the--remote-dataoption is not provided to thepytestcommand, or
if--remote-data=noneis provided, all tests that are marked withremote_datawill be skipped. All tests that are marked withinternet_offwill be executed.Sometimes it is useful to check that certain tests do not unexpectedly access
the internet. Strict remote data access checking can be enabled by settingremote_data_strict = truein the tested package’ssetup.cfgfile. If
this option is enabled, any test that attempts to access the network but is not
marked with@pytest.mark.remote_datawill fail.Providing either the--remote-dataoption, or--remote-data=anyto thepytestcommand line interface will cause all tests that are marked withremote-datato execute. Any tests that are marked withinternet_offwill be skipped.Running the tests with--remote-data=astropywill cause only tests that
receive remote data from Astropy data sources to be run. Tests with any other
data sources will be skipped. This is indicated in the test code by marking
test functions with@pytest.mark.remote_data(source='astropy').Running only the tests marked asremote_data, use the built-in pytest
machinery, e.g.,pytest-mremote_data--remote-data.In the future, we intend to support a configurable way to indicate specific
remote data sources in addition toastropy.Development StatusQuestions, bug reports, and feature requests can be submitted ongithub.LicenseThis plugin is licensed under a 3-clause BSD style license - see theLICENSE.rstfile.