Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAINT: Remove astropy.test(), should use pytest directly #16208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.

4 changes: 2 additions & 2 deletions astropy/utils/tests/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ def test_find_mod_objs():

# 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
MridulS marked this conversation as resolved.
Show resolved Hide resolved
assert "conf" in lnms
assert astropy.conf 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is doubled up. This line and l.308 should be combined into

be included by running ``pytest --remote-data=any``.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit out of date in general, since we now suggest to use tox. I'd either skip the example and go straight to For more details on... or, perhaps better, rewrite as,

   changes do not break existing code, by running the Astropy tests,
   e.g., by running::

      tox -e test

   For more details on running ...


Tests can also be run from the command line while in the package
root directory, e.g.::
Expand Down
19 changes: 9 additions & 10 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ or::
h5py beautifulsoup4 html5lib bleach pandas sortedcontainers \
pytz setuptools mpmath bottleneck jplephem asdf-astropy pyarrow

To also be able to run tests (see below) and support :ref:`builddocs` use the
following. We use ``pip`` for these packages to ensure getting the latest
releases which are compatible with the latest ``pytest`` and ``sphinx`` releases::

python -m pip install pytest-astropy sphinx-astropy

.. warning::

Attempting to use `pip <https://pip.pypa.io>`__ to upgrade your installation
Expand All @@ -108,11 +102,16 @@ 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::
To run tests after installing ``astropy`` we need to install ``pytest`` and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the changes are good as is, since we've not installed from source.

all other required dependencies. They are available as a meta package ``pytest-astropy``
on PyPI::

python -m pip install pytest-astropy

Once you have installed ``pytest-astropy`` you can run ``pytest`` to test the
installation::

import astropy
astropy.test()
pytest --pyargs astropy

The tests should run and print out any failures, which you can report at
the `Astropy issue tracker <https://github.com/astropy/astropy/issues>`_.
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
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ commands =
!cov-!double: pytest --pyargs astropy {toxinidir}/docs {env:MPLFLAGS} {posargs}
cov-!double: pytest --pyargs astropy {toxinidir}/docs {env:MPLFLAGS} --cov astropy --cov-config={toxinidir}/pyproject.toml --cov-report xml:{toxinidir}/coverage.xml {posargs}

double: python -c 'import sys; from astropy import test; test(); sys.exit(test())'
double: pytest --keep-duplicates --pyargs astropy astropy

pip_pre =
predeps: true
Expand Down