Astropy Testing Tools#
This section is primarily a reference for developers that want to understand or add to the Astropy testing machinery. See Testing Guidelines for an overview of running or writing the tests.
Details#
The dependencies used by the Astropy test runner are provided by a separate
package called pytest-astropy (see Pytest Plugins). This package provides the pytest
dependency itself, in addition to several pytest
plugins that are used by
Astropy, and will also be of general use to other packages.
Since the testing dependencies are not actually required to install or use
Astropy, in the pyproject.toml
file they are not included under the
[project]
section in dependencies
. Instead, they are listed under the
[project.optional-dependences]
in named sections such as test
or dev_all
.
In particular the test
dependencies are the minimal set of dependencies for running
astropy tests and you would use this primarily to check that tests pass without the
optional dependencies. This is not common and would normally be done with tox -e
test
.
astropy.tests.helper
Module#
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, pytest, or numpy.testing. This module contains primarily functionality specific to the astropy core package or packages that follow the Astropy package template.
Conversion Guide#
Some long-standing functionality has been removed. The following table maps them to what you should use instead.
Removed |
Use this |
---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Reference/API#
astropy.tests.helper Module#
Functions#
|
Test that an object follows our Unicode policy. |
|
Raise an assertion if two objects are not equal up to desired tolerance. |
|
Try to pickle an object. |
|
Check if the attributes of a and b are equal. |
|
Fixture to run all the tests for protocols 0 and 1, and -1 (most advanced). |
Astropy Test Runner#
When executing tests with packagename.test
the call to pytest is controlled
by the astropy.tests.runner.TestRunner
class.
The TestRunner
class is used to generate the
packagename.test
function, the test function generates a set of command line
arguments to pytest. The arguments to pytest are defined in the
run_tests
method, the arguments to
run_tests
and their respective logic are defined in methods of
TestRunner
decorated with the
keyword
decorator. For an example of this see
TestRunnerBase
. This design makes it easy for
packages to add or remove keyword arguments to their test runners, or define a
whole new set of arguments by subclassing from
TestRunnerBase
.
Reference/API#
astropy.tests.runner Module#
Classes#
|
A test runner for astropy tests. |
|
The base class for the TestRunner. |
|
A decorator to mark a method as keyword argument for the |