Astropy Testing helpers (astropy.tests.helper)

To ease development of tests that work with Astropy, the astropy.tests.helper module provides some utility functions to make tests that use Astropy conventions or classes easier to work with. e.g., functions to test for near-equality of Quantity objects.

The functionality here is not exhaustive, because much of the useful tools are either in the standard library, py.test, or numpy.testing. This module contains primarily functionality specific to Astropy or affiliated packages that follow the package template.

Note that this module also includes the remote_data marker, which is used to indicate a test accesses data from the internet while running. It is intended to be used as:

from astropy.tests.helper import remote_data

def test_something():
    This test downloads something from the internet
    # test code here ...

This test will now only run if the test suite is invoked as python test --remote-data.


astropy.tests.helper Module


enable_deprecations_as_exceptions([...]) Turn on the feature that turns deprecations into exceptions.
treat_deprecations_as_exceptions() Turn all DeprecationWarnings (which indicate deprecated uses of Python itself or Numpy, but not within Astropy, where we use our own deprecation warning class) into exceptions so that we find out about them early.
assert_follows_unicode_guidelines(x[, roundtrip]) Test that an object follows our Unicode policy.
quantity_allclose(a, b[, rtol, atol]) Returns True if two arrays are element-wise equal within a tolerance.
assert_quantity_allclose(actual, desired[, ...]) Raise an assertion if two objects are not equal up to desired tolerance.
check_pickling_recovery(original, protocol) Try to pickle an object.
pickle_protocol(request) Fixture to run all the tests for protocols 0 and 1, and -1 (most advanced).
generic_recursive_equality_test(a, b, ...) Check if the attributes of a and b are equal.


raises(exc) A decorator to mark that a test should raise a given exception.
catch_warnings(*classes) A high-powered version of warnings.catch_warnings to use for testing and to make sure that there is no dependence on the order in which the tests are run.