pytest-astropy-header


Namepytest-astropy-header JSON
Version 0.2.2 PyPI version JSON
download
home_pagehttps://github.com/astropy/pytest-astropy-header
Summarypytest plugin to add diagnostic information to the header of the test output
upload_time2022-09-06 20:44:46
maintainer
docs_urlNone
authorThe Astropy Developers
requires_python>=3.7
licenseBSD 3-Clause License
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            =====================
pytest-astropy-header
=====================

.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.5806492.svg
    :target: https://doi.org/10.5281/zenodo.5806492
    :alt: 10.5281/zenodo.5806492

.. image:: https://img.shields.io/pypi/v/pytest-astropy-header.svg
    :target: https://pypi.python.org/pypi/pytest-astropy-header
    :alt: PyPI

.. image:: https://github.com/astropy/pytest-astropy-header/workflows/CI/badge.svg
    :target: https://github.com/astropy/pytest-astropy-header/actions
    :alt: CI Status

This plugin package provides a way to include information about the system,
Python installation, and select dependencies in the header of the output when
running pytest. It can be used with packages that are not affiliated with the
Astropy project, but is optimized for use with Astropy-related projects.

Installation
------------

The ``pytest-astropy-header`` plugin can be installed using ``pip``::

    $ pip install pytest-astropy-header

It is also possible to install the latest development version from the source
repository::

    $ git clone https://github.com/astropy/pytest-astropy-header
    $ cd pytest-astropy-header
    $ pip install .

In either case, the plugin will automatically be registered for use with
``pytest``.

User guide
----------

The plugin provided by this package makes it easy to include a header
with diagnostic information before running the tests, e.g.::

    Running tests in astropy.

    Date: 2019-09-02T23:33:43

    Platform: Darwin-18.7.0-x86_64-i386-64bit

    Executable: /Users/tom/python/dev/bin/python3.7

    Full Python Version:
    3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)
    [Clang 6.0 (clang-600.0.57)]

    encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8
    byteorder: little
    float info: dig: 15, mant_dig: 15

    Package versions:
    numpy: 1.16.4
    scipy: 1.3.0
    matplotlib: 3.1.1
    h5py: 2.9.0
    pandas: 0.24.2
    astropy: 4.0.dev25634

    Using Astropy options: remote_data: none.

The most robust way to enable the plugin in a way that will work regardless of
how the tests are run (e.g. via ``pytest``, or ``package.test()``)
is to add the following to a ``conftest.py`` file that is
inside your package::

    def pytest_configure(config):
        config.option.astropy_header = True

**or** add the following to your ``setup.cfg``::

    [tool:pytest]
    astropy_header = true

By default, a few packages will be shown, but you may want to customize how the
packages appear. As for enabling the plugin, the most robust way to do this to
be compatible with different astropy versions is via the ``conftest.py`` file::

    try:
        from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS
    except ImportError:  # In case this plugin is not installed
        PYTEST_HEADER_MODULES = {}
        TESTED_VERSIONS = {}

    # This really depends on how you set up your package version,
    # modify as needed.
    from mypackage import __version__ as version

    def pytest_configure(config):
        config.option.astropy_header = True  # If you do not have it in setup.cfg
        PYTEST_HEADER_MODULES.pop('Pandas')
        PYTEST_HEADER_MODULES['scikit-image'] = 'skimage'
        TESTED_VERSIONS['mypackage'] = version

The key to ``PYTEST_HEADER_MODULES`` should be the name that will be displayed
in the header, and the value should be the name of the Python module.

If you would like to append other text to the end of the header, you can do this
by implementing your own ``pytest_report_header()`` function in the
``conftest.py`` file in your package. For example, to add a custom footer to the
end of the Astropy header, you could define::

    def pytest_report_header(config):
        footer = ("This is some custom text that will appear after the "
                  "Astropy pytest header!")
        return footer + "\n"


Migrating from the astropy header plugin to pytest-astropy-header
-----------------------------------------------------------------

**Note: pytest-astropy-header no longer supports astropy<4.
This section is only kept for historical reason.**

Before the v4.0 release of the core astropy package, the plugin that handles the
header of the testing output described above lived in
``astropy.tests.plugins.display``. A few steps are now needed to update packages
to make sure that only the pytest-astropy-header version is used instead. These should
be done in addition to the configuration mentioned in the previous section.

First, you should be able to significantly simplify the ``conftest.py`` file by
replacing e.g.::

    from astropy.version import version as astropy_version
    if astropy_version < '3.0':
        # With older versions of Astropy, we actually need to import the pytest
        # plugins themselves in order to make them discoverable by pytest.
        from astropy.tests.pytest_plugins import *
    else:
        # As of Astropy 3.0, the pytest plugins provided by Astropy are
        # automatically made available when Astropy is installed. This means it's
        # not necessary to import them here, but we still need to import global
        # variables that are used for configuration.
        from astropy.tests.plugins.display import (pytest_report_header,
                                                   PYTEST_HEADER_MODULES,
                                                   TESTED_VERSIONS)

    # Customize the following lines to add/remove entries from
    # the list of packages for which version numbers are displayed when running
    # the tests. Making it pass for KeyError is essential in some cases when
    # the package uses other astropy affiliated packages.
    try:
        PYTEST_HEADER_MODULES['Astropy'] = 'astropy'
        del PYTEST_HEADER_MODULES['h5py']
    except KeyError:
        pass

    # This is to figure out the package version, rather than
    # using Astropy's
    from .version import version, astropy_helpers_version

    packagename = os.path.basename(os.path.dirname(__file__))
    TESTED_VERSIONS[packagename] = version
    TESTED_VERSIONS['astropy_helpers'] = astropy_helpers_version

with e.g.::

    import os

    from astropy.version import version as astropy_version
    if astropy_version < '3.0':
        from astropy.tests.pytest_plugins import *
        del pytest_report_header
    else:
        from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS


    def pytest_configure(config):

        config.option.astropy_header = True

        PYTEST_HEADER_MODULES.pop('Pandas', None)
        PYTEST_HEADER_MODULES['scikit-image'] = 'skimage'

        from .version import version, astropy_helpers_version
        packagename = os.path.basename(os.path.dirname(__file__))
        TESTED_VERSIONS[packagename] = version
        TESTED_VERSIONS['astropy_helpers'] = astropy_helpers_version

Note that while you will need to use a recent version of pytest-astropy for this
to work, it should work with Astropy 2.0 onwards without requiring all the
``try...except`` for imports.

Next check all of your ``conftest.py`` files and be sure to remove the old
plugin from lists such as::

    pytest_plugins = [
      'astropy.tests.plugins.display',
    ]

Development Status
------------------

Questions, bug reports, and feature requests can be submitted on `github`_.

.. _github: https://github.com/astropy/pytest-astropy

License
-------

This package is licensed under a 3-clause BSD style license - see the
``LICENSE.rst`` file.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/astropy/pytest-astropy-header",
    "name": "pytest-astropy-header",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "The Astropy Developers",
    "author_email": "astropy.team@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/0f/ed/1caf921a7612024544fe2217e2590a2ef3e80396c3ac098d47cbc924df0b/pytest-astropy-header-0.2.2.tar.gz",
    "platform": null,
    "description": "=====================\npytest-astropy-header\n=====================\n\n.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.5806492.svg\n    :target: https://doi.org/10.5281/zenodo.5806492\n    :alt: 10.5281/zenodo.5806492\n\n.. image:: https://img.shields.io/pypi/v/pytest-astropy-header.svg\n    :target: https://pypi.python.org/pypi/pytest-astropy-header\n    :alt: PyPI\n\n.. image:: https://github.com/astropy/pytest-astropy-header/workflows/CI/badge.svg\n    :target: https://github.com/astropy/pytest-astropy-header/actions\n    :alt: CI Status\n\nThis plugin package provides a way to include information about the system,\nPython installation, and select dependencies in the header of the output when\nrunning pytest. It can be used with packages that are not affiliated with the\nAstropy project, but is optimized for use with Astropy-related projects.\n\nInstallation\n------------\n\nThe ``pytest-astropy-header`` plugin can be installed using ``pip``::\n\n    $ pip install pytest-astropy-header\n\nIt is also possible to install the latest development version from the source\nrepository::\n\n    $ git clone https://github.com/astropy/pytest-astropy-header\n    $ cd pytest-astropy-header\n    $ pip install .\n\nIn either case, the plugin will automatically be registered for use with\n``pytest``.\n\nUser guide\n----------\n\nThe plugin provided by this package makes it easy to include a header\nwith diagnostic information before running the tests, e.g.::\n\n    Running tests in astropy.\n\n    Date: 2019-09-02T23:33:43\n\n    Platform: Darwin-18.7.0-x86_64-i386-64bit\n\n    Executable: /Users/tom/python/dev/bin/python3.7\n\n    Full Python Version:\n    3.7.4 (v3.7.4:e09359112e, Jul  8 2019, 14:54:52)\n    [Clang 6.0 (clang-600.0.57)]\n\n    encodings: sys: utf-8, locale: UTF-8, filesystem: utf-8\n    byteorder: little\n    float info: dig: 15, mant_dig: 15\n\n    Package versions:\n    numpy: 1.16.4\n    scipy: 1.3.0\n    matplotlib: 3.1.1\n    h5py: 2.9.0\n    pandas: 0.24.2\n    astropy: 4.0.dev25634\n\n    Using Astropy options: remote_data: none.\n\nThe most robust way to enable the plugin in a way that will work regardless of\nhow the tests are run (e.g. via ``pytest``, or ``package.test()``)\nis to add the following to a ``conftest.py`` file that is\ninside your package::\n\n    def pytest_configure(config):\n        config.option.astropy_header = True\n\n**or** add the following to your ``setup.cfg``::\n\n    [tool:pytest]\n    astropy_header = true\n\nBy default, a few packages will be shown, but you may want to customize how the\npackages appear. As for enabling the plugin, the most robust way to do this to\nbe compatible with different astropy versions is via the ``conftest.py`` file::\n\n    try:\n        from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS\n    except ImportError:  # In case this plugin is not installed\n        PYTEST_HEADER_MODULES = {}\n        TESTED_VERSIONS = {}\n\n    # This really depends on how you set up your package version,\n    # modify as needed.\n    from mypackage import __version__ as version\n\n    def pytest_configure(config):\n        config.option.astropy_header = True  # If you do not have it in setup.cfg\n        PYTEST_HEADER_MODULES.pop('Pandas')\n        PYTEST_HEADER_MODULES['scikit-image'] = 'skimage'\n        TESTED_VERSIONS['mypackage'] = version\n\nThe key to ``PYTEST_HEADER_MODULES`` should be the name that will be displayed\nin the header, and the value should be the name of the Python module.\n\nIf you would like to append other text to the end of the header, you can do this\nby implementing your own ``pytest_report_header()`` function in the\n``conftest.py`` file in your package. For example, to add a custom footer to the\nend of the Astropy header, you could define::\n\n    def pytest_report_header(config):\n        footer = (\"This is some custom text that will appear after the \"\n                  \"Astropy pytest header!\")\n        return footer + \"\\n\"\n\n\nMigrating from the astropy header plugin to pytest-astropy-header\n-----------------------------------------------------------------\n\n**Note: pytest-astropy-header no longer supports astropy<4.\nThis section is only kept for historical reason.**\n\nBefore the v4.0 release of the core astropy package, the plugin that handles the\nheader of the testing output described above lived in\n``astropy.tests.plugins.display``. A few steps are now needed to update packages\nto make sure that only the pytest-astropy-header version is used instead. These should\nbe done in addition to the configuration mentioned in the previous section.\n\nFirst, you should be able to significantly simplify the ``conftest.py`` file by\nreplacing e.g.::\n\n    from astropy.version import version as astropy_version\n    if astropy_version < '3.0':\n        # With older versions of Astropy, we actually need to import the pytest\n        # plugins themselves in order to make them discoverable by pytest.\n        from astropy.tests.pytest_plugins import *\n    else:\n        # As of Astropy 3.0, the pytest plugins provided by Astropy are\n        # automatically made available when Astropy is installed. This means it's\n        # not necessary to import them here, but we still need to import global\n        # variables that are used for configuration.\n        from astropy.tests.plugins.display import (pytest_report_header,\n                                                   PYTEST_HEADER_MODULES,\n                                                   TESTED_VERSIONS)\n\n    # Customize the following lines to add/remove entries from\n    # the list of packages for which version numbers are displayed when running\n    # the tests. Making it pass for KeyError is essential in some cases when\n    # the package uses other astropy affiliated packages.\n    try:\n        PYTEST_HEADER_MODULES['Astropy'] = 'astropy'\n        del PYTEST_HEADER_MODULES['h5py']\n    except KeyError:\n        pass\n\n    # This is to figure out the package version, rather than\n    # using Astropy's\n    from .version import version, astropy_helpers_version\n\n    packagename = os.path.basename(os.path.dirname(__file__))\n    TESTED_VERSIONS[packagename] = version\n    TESTED_VERSIONS['astropy_helpers'] = astropy_helpers_version\n\nwith e.g.::\n\n    import os\n\n    from astropy.version import version as astropy_version\n    if astropy_version < '3.0':\n        from astropy.tests.pytest_plugins import *\n        del pytest_report_header\n    else:\n        from pytest_astropy_header.display import PYTEST_HEADER_MODULES, TESTED_VERSIONS\n\n\n    def pytest_configure(config):\n\n        config.option.astropy_header = True\n\n        PYTEST_HEADER_MODULES.pop('Pandas', None)\n        PYTEST_HEADER_MODULES['scikit-image'] = 'skimage'\n\n        from .version import version, astropy_helpers_version\n        packagename = os.path.basename(os.path.dirname(__file__))\n        TESTED_VERSIONS[packagename] = version\n        TESTED_VERSIONS['astropy_helpers'] = astropy_helpers_version\n\nNote that while you will need to use a recent version of pytest-astropy for this\nto work, it should work with Astropy 2.0 onwards without requiring all the\n``try...except`` for imports.\n\nNext check all of your ``conftest.py`` files and be sure to remove the old\nplugin from lists such as::\n\n    pytest_plugins = [\n      'astropy.tests.plugins.display',\n    ]\n\nDevelopment Status\n------------------\n\nQuestions, bug reports, and feature requests can be submitted on `github`_.\n\n.. _github: https://github.com/astropy/pytest-astropy\n\nLicense\n-------\n\nThis package is licensed under a 3-clause BSD style license - see the\n``LICENSE.rst`` file.\n",
    "bugtrack_url": null,
    "license": "BSD 3-Clause License",
    "summary": "pytest plugin to add diagnostic information to the header of the test output",
    "version": "0.2.2",
    "project_urls": {
        "Homepage": "https://github.com/astropy/pytest-astropy-header"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "10db3bde86b77504c01f8cc174ccce13029aa5e26daaae9fcdc08826f1f0c7a5",
                "md5": "6e81b4759c445d62583ebb6589f20152",
                "sha256": "6088db080166d59f27c045247ad038ac8656f7c35d5c979cb87ed9a8f7efdee0"
            },
            "downloads": -1,
            "filename": "pytest_astropy_header-0.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "6e81b4759c445d62583ebb6589f20152",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7815,
            "upload_time": "2022-09-06T20:44:45",
            "upload_time_iso_8601": "2022-09-06T20:44:45.040277Z",
            "url": "https://files.pythonhosted.org/packages/10/db/3bde86b77504c01f8cc174ccce13029aa5e26daaae9fcdc08826f1f0c7a5/pytest_astropy_header-0.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0fed1caf921a7612024544fe2217e2590a2ef3e80396c3ac098d47cbc924df0b",
                "md5": "244291d7fe71f0a7d3920f72ecddf757",
                "sha256": "77891101c94b75a8ca305453b879b318ab6001b370df02be2c0b6d1bb322db10"
            },
            "downloads": -1,
            "filename": "pytest-astropy-header-0.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "244291d7fe71f0a7d3920f72ecddf757",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9914,
            "upload_time": "2022-09-06T20:44:46",
            "upload_time_iso_8601": "2022-09-06T20:44:46.824172Z",
            "url": "https://files.pythonhosted.org/packages/0f/ed/1caf921a7612024544fe2217e2590a2ef3e80396c3ac098d47cbc924df0b/pytest-astropy-header-0.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-09-06 20:44:46",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "astropy",
    "github_project": "pytest-astropy-header",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-astropy-header"
}
        
Elapsed time: 0.56841s