Skip to content

Commit

Permalink
MAINT: Remove astropy.test(), should use pytest directly
Browse files Browse the repository at this point in the history
  • Loading branch information
MridulS committed Mar 17, 2024
1 parent f52a09b commit b1451d0
Show file tree
Hide file tree
Showing 8 changed files with 3 additions and 154 deletions.
6 changes: 0 additions & 6 deletions astropy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,6 @@ class astronomical_constants(base_constants_version):
)


# Create the test() function
from .tests.runner import TestRunner

test = TestRunner.make_test_runner_in(__path__[0])


# if we are *not* in setup mode, import the logger and possibly populate the
# configuration file with the defaults
def _initialize_astropy():
Expand Down
1 change: 0 additions & 1 deletion astropy/tests/tests/test_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,4 @@ def test_toplevel_namespace():
d = dir(astropy)
assert "os" not in d
assert "log" in d
assert "test" in d
assert "sys" not in d
21 changes: 0 additions & 21 deletions astropy/tests/tests/test_run_tests.py

This file was deleted.

6 changes: 0 additions & 6 deletions astropy/utils/tests/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,6 @@ def test_find_mod_objs():

# this import is after the above call intentionally to make sure
# find_mod_objs properly imports astropy on its own
import astropy

# just check for astropy.test ... other things might be added, so we
# shouldn't check that it's the only thing
assert "test" in lnms
assert astropy.test in objs

with pytest.warns(AstropyDeprecationWarning, match=deprecation_message):
lnms, fqns, objs = find_mod_objs(__name__, onlylocals=False)
Expand Down
59 changes: 2 additions & 57 deletions docs/development/testguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -160,51 +160,6 @@ and this works for ``.rst`` files too::

pytest astropy/wcs/index.rst

.. _astropy.test():

astropy.test()
==============

Tests can be run from an installed version of Astropy with::

import astropy
astropy.test()

This will run all the default tests for Astropy (but will not run the
documentation tests in the ``.rst`` documentation since those files are
not installed).

Tests for a specific package can be run by specifying the package in the call
to the ``test()`` function::

astropy.test(package='io.fits')

This method works only with package names that can be mapped to Astropy
directories. As an alternative you can test a specific directory or file
with the ``test_path`` option::

astropy.test(test_path='wcs/tests/test_wcs.py')

The ``test_path`` must be specified either relative to the working directory
or absolutely.

By default `astropy.test()`_ will skip tests which retrieve data from the
internet. To turn these tests on use the ``remote_data`` flag::

astropy.test(package='io.fits', remote_data=True)

In addition, the ``test`` function supports any of the options that can be
passed to :ref:`pytest.main() <pytest:pytest.main-usage>`
and convenience options ``verbose=`` and ``pastebin=``.

Enable PEP8 compliance testing with ``pep8=True`` in the call to
``astropy.test``. This will enable PEP8 checking and disable regular tests.

Astropy Test Function
---------------------

.. autofunction:: astropy.test

Test-running options
====================

Expand Down Expand Up @@ -245,11 +200,6 @@ commandline option. For example, to use 4 processes::
Pass ``-n auto`` to create the same number of processes as cores
on your machine.

Similarly, this feature can be invoked from ``astropy.test``::

>>> import astropy
>>> astropy.test(parallel=4)

.. _writing-tests:

Writing tests
Expand Down Expand Up @@ -353,8 +303,8 @@ local copy of the file.
Tests that may retrieve remote data should be marked with the
``@pytest.mark.remote_data`` decorator, or, if a doctest, flagged with the
``REMOTE_DATA`` flag. Tests marked in this way will be skipped by default by
``astropy.test()`` to prevent test runs from taking too long. These tests can
be run by ``astropy.test()`` by adding the ``remote_data='any'`` flag. Turn on
``pytest`` to prevent test runs from taking too long. These tests can
be run by ``pytest`` by adding the ``remote_data='any'`` flag. Turn on
the remote data tests at the command line with ``pytest --remote-data=any``.

It is possible to mark tests using
Expand Down Expand Up @@ -874,11 +824,6 @@ astropy source code or documentation, or in packages using the Astropy test
running framework. For example doctests and detailed documentation on how to
write them, see the full :mod:`doctest` documentation.

.. note::

Since the narrative Sphinx documentation is not installed alongside the
astropy source code, it can only be tested by running ``pytest`` directly (or
via tox), not by ``import astropy; astropy.test()``.

For more information on the ``pytest-doctestplus`` plugin used by Astropy, see
:ref:`doctestplus-plugin`.
Expand Down
12 changes: 1 addition & 11 deletions docs/development/workflow/development_workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,7 @@ In more detail
bug as a different set of changes.

#. Test that your changes do not lead to *regressions*, i.e. that your
changes do not break existing code, by running the Astropy tests. You can
run all of the Astropy tests from ipython with::

import astropy
astropy.test()

If your change involves only a small part of Astropy, e.g. Time, you can
run just those tests::

import astropy
astropy.test(package='time')
changes do not break existing code, by running the Astropy tests.

Tests can also be run from the command line while in the package
root directory, e.g.::
Expand Down
27 changes: 0 additions & 27 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -101,33 +101,6 @@ releases which are compatible with the latest ``pytest`` and ``sphinx`` releases
Attempting to use `pip <https://pip.pypa.io>`__ to upgrade your installation
of ``astropy`` itself may result in a corrupted installation.

.. _testing_installed_astropy:

Testing an Installed ``astropy``
================================

{% if is_development %}

The easiest way to test if your installed version of ``astropy`` is running
correctly is to use the :ref:`astropy.test()` function::

import astropy
astropy.test()

The tests should run and print out any failures, which you can report at
the `Astropy issue tracker <https://github.com/astropy/astropy/issues>`_.

This way of running the tests may not work if you do it in the ``astropy`` source
distribution. See :ref:`sourcebuildtest` for how to run the tests from the
source code directory, or :ref:`running-tests` for more details.

{%else%}

See the :ref:`latest documentation on how to test your installed version of
astropy <astropy-dev:testing_installed_astropy>`.

{%endif%}

.. _astropy-main-req:

Requirements
Expand Down
25 changes: 0 additions & 25 deletions docs/known_issues.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,28 +293,3 @@ see something like::

If so, you can go ahead and try running ``pip`` again (in the new
terminal).


Failing Logging Tests When Running the Tests in IPython
-------------------------------------------------------

When running the Astropy tests using ``astropy.test()`` in an IPython
interpreter, some of the tests in the ``astropy/tests/test_logger.py`` *might*
fail depending on the version of IPython or other factors.
This is due to mutually incompatible behaviors in IPython and pytest, and is
not due to a problem with the test itself or the feature being tested.

See: https://github.com/astropy/astropy/issues/717

Test runner fails when asdf-astropy is installed
------------------------------------------------

When you have ``asdf-astropy`` installed and then run ``astropy.test()``,
you will see a traceback that complains about the following::

PytestAssertRewriteWarning: Module already imported so cannot be rewritten: asdf

To run ``astropy.test()`` anyway, please first uninstall ``asdf-astropy``.
If you do not want to do that, use ``pytest`` or ``tox`` instead of the test runner.

See: https://github.com/astropy/astropy/issues/16165

0 comments on commit b1451d0

Please sign in to comment.