././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2287107 pytest-astropy-header-0.2.2/0000755000175100001710000000000014305730424015371 5ustar00runnerdocker././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2247105 pytest-astropy-header-0.2.2/.github/0000755000175100001710000000000014305730424016731 5ustar00runnerdocker././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2247105 pytest-astropy-header-0.2.2/.github/workflows/0000755000175100001710000000000014305730424020766 5ustar00runnerdocker././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/.github/workflows/ci_workflows.yml0000644000175100001710000000106014305730402024212 0ustar00runnerdockername: CI on: pull_request: push: schedule: # Run every Sunday at 05:53 UTC - cron: 53 5 * * 0 jobs: tests: uses: OpenAstronomy/github-actions-workflows/.github/workflows/tox.yml@v1 with: envs: | - linux: py37-test-pytest46 - windows: py37-test-pytest50 - macos: py38-test-pytest51 - linux: py38-test-pytest52 - windows: py39-test-pytest53 - macos: py39-test-pytest60 - linux: py39-test-pytest61 - windows: py310-test-pytest62 - linux: py310-test-pytestdev ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/.github/workflows/publish.yml0000644000175100001710000000072714305730402023161 0ustar00runnerdockername: Release on: pull_request: push: tags: - '*' jobs: publish: uses: OpenAstronomy/github-actions-workflows/.github/workflows/publish_pure_python.yml@v1 if: ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) || contains(github.event.pull_request.labels.*.name, 'Build wheels')) with: test_extras: test test_command: pytest $GITHUB_WORKSPACE/tests secrets: pypi_token: ${{ secrets.PYPI_API_TOKEN }} ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/.gitignore0000644000175100001710000000116314305730402017356 0ustar00runnerdocker# Compiled files *.py[cod] *.a *.o *.so *.pyd __pycache__ # Ignore .c files by default to avoid including generated code. If you want to # add a non-generated .c extension, use `git add -f filename.c`. *.c # Other generated files MANIFEST pytest_astropy_header/version.py pip-wheel-metadata/ # Sphinx _build _generated docs/api docs/generated # Packages/installer info *.egg *.egg-info dist build eggs .eggs parts bin var sdist develop-eggs .installed.cfg distribute-*.tar.gz # Other .cache .tox .*.swp .*.swo *~ .project .pydevproject .settings .coverage cover htmlcov .pytest_cache # Mac OSX .DS_Store # PyCharm .idea ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/CHANGES.rst0000644000175100001710000000167414305730402017177 0ustar00runnerdocker0.2.2 (2022-09-06) ================== - The plugin is now aware of the ``run_slow`` and ``run_hugemem`` options introduced in ``pytest-astropy`` version 0.10.0. [#48] 0.2.1 (2022-03-09) ================== - Fixed compatibility with ``astropy``. [#43] 0.2.0 (2021-12-27) ================== - Suppressed ``PytestAssertRewriteWarning``. [#4] - Do not show astropy-helpers version in packages that don't use it. [#16] - Removed compatibility code for ``astropy`` < 4.0, and for ``astropy-helpers``. [#32] - Removed ``astropy`` dependency. [#19, #34] - Bumped minimum supported Python version to 3.7 and various infrastructure updates. [#23, #39] 0.1.2 (2019-12-18) ================== - Handle the case where the astropy version is 'unknown'. [#11] - Fix declaration of test dependencies. [#9] 0.1.1 (2019-10-25) ================== - Make plugin not crash if astropy is not installed. [#1] 0.1 (2019-10-25) ================ - Initial release. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/LICENSE.rst0000644000175100001710000000272314305730402017205 0ustar00runnerdockerCopyright (c) 2019, Astropy Developers All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the Astropy Team nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/MANIFEST.in0000644000175100001710000000015014305730402017117 0ustar00runnerdockerinclude LICENSE.rst include README.rst include CHANGES.rst include setup.cfg global-exclude *.pyc *.o ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2287107 pytest-astropy-header-0.2.2/PKG-INFO0000644000175100001710000002032714305730424016472 0ustar00runnerdockerMetadata-Version: 2.1 Name: pytest-astropy-header Version: 0.2.2 Summary: pytest plugin to add diagnostic information to the header of the test output Home-page: https://github.com/astropy/pytest-astropy-header Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD 3-Clause License Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: BSD License Requires-Python: >=3.7 Description-Content-Type: text/x-rst Provides-Extra: test License-File: LICENSE.rst ===================== 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. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/README.rst0000644000175100001710000001657314305730402017070 0ustar00runnerdocker===================== 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. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/pyproject.toml0000644000175100001710000000021414305730402020276 0ustar00runnerdocker[build-system] requires = ["setuptools>=30.3.0", "setuptools_scm", "wheel"] build-backend = 'setuptools.build_meta' ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2247105 pytest-astropy-header-0.2.2/pytest_astropy_header/0000755000175100001710000000000014305730424022012 5ustar00runnerdocker././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/pytest_astropy_header/__init__.py0000644000175100001710000000016514305730402024121 0ustar00runnerdocker# Licensed under a 3-clause BSD style license - see LICENSE.rst from .version import version as __version__ # noqa ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/pytest_astropy_header/display.py0000644000175100001710000001071714305730402024033 0ustar00runnerdocker# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This plugin provides customization of the header displayed by pytest for reporting purposes. PYTEST_DONT_REWRITE """ import datetime import importlib import locale import os import sys TESTED_VERSIONS = {} DEFAULT_PACKAGES = ("Numpy", "Scipy", "Matplotlib", "h5py", "Pandas") PYTEST_HEADER_MODULES = {pkg: pkg.lower() for pkg in DEFAULT_PACKAGES} # This import is needed so astropy can use pytest-astropy-header. # See https://github.com/astropy/pytest-astropy-header/issues/41 try: import astropy # noqa: F401 except ImportError: pass def pytest_addoption(parser): group = parser.getgroup("astropy header options") group.addoption('--astropy-header', action='store_true', help="Show the pytest-astropy header") group.addoption('--astropy-header-packages', default=None, help="Comma-separated list of packages to include in the header") parser.addini('astropy_header', type="bool", help="Show the pytest-astropy header") parser.addini('astropy_header_packages', type='linelist', help="Comma-separated list of packages to include in the header") def pytest_report_header(config): if not config.getoption("astropy_header") and not config.getini("astropy_header"): return astropy_header_packages_option = config.getoption("astropy_header_packages") astropy_header_packages_ini = config.getini("astropy_header_packages") if astropy_header_packages_option is not None: if isinstance(astropy_header_packages_option, str): astropy_header_packages_option = [x.strip() for x in astropy_header_packages_option.split(',')] packages_to_display = {x: x for x in astropy_header_packages_option} elif len(astropy_header_packages_ini) > 0: if len(astropy_header_packages_ini) == 1: astropy_header_packages_ini = [x.strip() for x in astropy_header_packages_ini[0].split(',')] packages_to_display = {x: x for x in astropy_header_packages_ini} else: packages_to_display = PYTEST_HEADER_MODULES try: stdoutencoding = sys.stdout.encoding or 'ascii' except AttributeError: stdoutencoding = 'ascii' args = config.args s = '' for pkg, version in TESTED_VERSIONS.items(): s += f"\nRunning tests with {pkg} version {version}.\n" # Per https://github.com/astropy/astropy/pull/4204, strip the rootdir from # each directory argument if hasattr(config, 'rootdir'): rootdir = str(config.rootdir) if not rootdir.endswith(os.sep): rootdir += os.sep dirs = [arg[len(rootdir):] if arg.startswith(rootdir) else arg for arg in args] else: dirs = args s += "Running tests in {}.\n\n".format(" ".join(dirs)) s += "Date: {}\n\n".format(datetime.datetime.now().isoformat()[:19]) import warnings from platform import platform plat = platform() if isinstance(plat, bytes): plat = plat.decode(stdoutencoding, 'replace') s += f"Platform: {plat}\n\n" s += f"Executable: {sys.executable}\n\n" s += f"Full Python Version: \n{sys.version}\n\n" s += "encodings: sys: {}, locale: {}, filesystem: {}".format( sys.getdefaultencoding(), locale.getpreferredencoding(), sys.getfilesystemencoding()) s += '\n' s += f"byteorder: {sys.byteorder}\n" s += "float info: dig: {0.dig}, mant_dig: {0.dig}\n\n".format( sys.float_info) s += "Package versions: \n" for module_display, module_name in packages_to_display.items(): try: with warnings.catch_warnings(): warnings.filterwarnings('ignore', category=DeprecationWarning) module = importlib.import_module(module_name) except ImportError: s += f"{module_display}: not available\n" else: try: version = module.__version__ except AttributeError: version = 'unknown (no __version__ attribute)' s += f"{module_display}: {version}\n" s += "\n" opts = [] for op in ("remote_data", "pep8", "run_slow", "run_hugemem"): op_value = getattr(config.option, op, None) if op_value: if isinstance(op_value, str): op = ': '.join((op, op_value)) opts.append(op) if opts: s += "Using Astropy options: {}.\n".format(", ".join(opts)) return s ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header/version.py0000644000175100001710000000026014305730424024047 0ustar00runnerdocker# coding: utf-8 # file generated by setuptools_scm # don't change, don't track in version control __version__ = version = '0.2.2' __version_tuple__ = version_tuple = (0, 2, 2) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2287107 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/0000755000175100001710000000000014305730424023504 5ustar00runnerdocker././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/PKG-INFO0000644000175100001710000002032714305730424024605 0ustar00runnerdockerMetadata-Version: 2.1 Name: pytest-astropy-header Version: 0.2.2 Summary: pytest plugin to add diagnostic information to the header of the test output Home-page: https://github.com/astropy/pytest-astropy-header Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD 3-Clause License Classifier: Development Status :: 3 - Alpha Classifier: Intended Audience :: Developers Classifier: Programming Language :: Python :: 3 :: Only Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Operating System :: OS Independent Classifier: License :: OSI Approved :: BSD License Requires-Python: >=3.7 Description-Content-Type: text/x-rst Provides-Extra: test License-File: LICENSE.rst ===================== 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. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/SOURCES.txt0000644000175100001710000000113214305730424025365 0ustar00runnerdocker.gitignore CHANGES.rst LICENSE.rst MANIFEST.in README.rst pyproject.toml setup.cfg setup.py tox.ini .github/workflows/ci_workflows.yml .github/workflows/publish.yml pytest_astropy_header/__init__.py pytest_astropy_header/display.py pytest_astropy_header/version.py pytest_astropy_header.egg-info/PKG-INFO pytest_astropy_header.egg-info/SOURCES.txt pytest_astropy_header.egg-info/dependency_links.txt pytest_astropy_header.egg-info/entry_points.txt pytest_astropy_header.egg-info/not-zip-safe pytest_astropy_header.egg-info/requires.txt pytest_astropy_header.egg-info/top_level.txt tests/test_display.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/dependency_links.txt0000644000175100001710000000000114305730424027552 0ustar00runnerdocker ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/entry_points.txt0000644000175100001710000000010114305730424026772 0ustar00runnerdocker[pytest11] pytest_astropy_header = pytest_astropy_header.display ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/not-zip-safe0000644000175100001710000000000114305730424025732 0ustar00runnerdocker ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/requires.txt0000644000175100001710000000004714305730424026105 0ustar00runnerdockerpytest>=4.6 [test] numpy astropy>=4.0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497044.0 pytest-astropy-header-0.2.2/pytest_astropy_header.egg-info/top_level.txt0000644000175100001710000000002614305730424026234 0ustar00runnerdockerpytest_astropy_header ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2287107 pytest-astropy-header-0.2.2/setup.cfg0000644000175100001710000000206514305730424017215 0ustar00runnerdocker[metadata] name = pytest-astropy-header description = pytest plugin to add diagnostic information to the header of the test output long_description = file:README.rst long_description_content_type = text/x-rst author = The Astropy Developers author_email = astropy.team@gmail.com license = BSD 3-Clause License url = https://github.com/astropy/pytest-astropy-header classifiers = Development Status :: 3 - Alpha Intended Audience :: Developers Programming Language :: Python :: 3 :: Only Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Operating System :: OS Independent License :: OSI Approved :: BSD License [options] zip_safe = False packages = find: python_requires = >=3.7 setup_requires = setuptools_scm install_requires = pytest>=4.6 [options.extras_require] test = numpy astropy>=4.0 [options.entry_points] pytest11 = pytest_astropy_header = pytest_astropy_header.display [flake8] max-line-length = 125 [egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/setup.py0000755000175100001710000000023014305730402017075 0ustar00runnerdocker#!/usr/bin/env python import os from setuptools import setup setup(use_scm_version={'write_to': os.path.join('pytest_astropy_header', 'version.py')}) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1662497044.2287107 pytest-astropy-header-0.2.2/tests/0000755000175100001710000000000014305730424016533 5ustar00runnerdocker././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/tests/test_display.py0000644000175100001710000001411314305730402021605 0ustar00runnerdockerimport pytest import numpy NUMPY_VERSION = numpy.__version__ pytest_plugins = ['pytester'] def extract_package_version_lines(output): lines = [] in_section = False for line in output.splitlines(): if line.strip() == 'Package versions:': in_section = True elif in_section: if line.strip() == "": break else: lines.append(line) return lines def test_default(testdir, capsys): testdir.inline_run() out, err = capsys.readouterr() assert 'Package versions:' not in out @pytest.mark.parametrize('method', ['cli', 'ini', 'conftest']) def test_enabled(testdir, capsys, method): if method == 'cli': testdir.inline_run("--astropy-header") elif method == 'ini': testdir.makeini(""" [pytest] astropy_header = yes """) testdir.inline_run() elif method == 'conftest': testdir.makeconftest(""" def pytest_configure(config): config.option.astropy_header = True """) testdir.inline_run() out, err = capsys.readouterr() lines = extract_package_version_lines(out) assert len(lines) == 5 assert lines[0].startswith('Numpy: ') assert lines[1].startswith('Scipy: ') assert lines[2].startswith('Matplotlib: ') assert lines[3].startswith('h5py: ') assert lines[4].startswith('Pandas: ') @pytest.mark.parametrize('method', ['ini', 'conftest']) def test_explicit_disable(testdir, capsys, method): if method == 'ini': testdir.makeini(""" [pytest] astropy_header = no """) testdir.inline_run() elif method == 'conftest': testdir.makeconftest(""" def pytest_configure(config): config.option.astropy_header = False """) testdir.inline_run() out, err = capsys.readouterr() assert 'Package versions:' not in out @pytest.mark.parametrize('method', ['cli', 'ini', 'ini_list', 'conftest']) def test_override_package_single(testdir, capsys, method): if method == 'cli': testdir.inline_run("--astropy-header", "--astropy-header-packages=numpy") elif method == 'ini': testdir.makeini(""" [pytest] astropy_header = yes astropy_header_packages = numpy """) testdir.inline_run() elif method == 'ini_list': testdir.makeini(""" [pytest] astropy_header = yes astropy_header_packages = numpy """) testdir.inline_run() elif method == 'conftest': testdir.makeconftest(""" def pytest_configure(config): config.option.astropy_header = True config.option.astropy_header_packages = ['numpy'] """) testdir.inline_run() out, err = capsys.readouterr() lines = extract_package_version_lines(out) assert len(lines) == 1 assert lines[0] == f'numpy: {NUMPY_VERSION}' @pytest.mark.parametrize('method', ['cli', 'ini', 'ini_list', 'conftest']) def test_override_package_multiple(testdir, capsys, method): if method == 'cli': testdir.inline_run("--astropy-header", "--astropy-header-packages=numpy,pandas") elif method == 'ini': testdir.makeini(""" [pytest] astropy_header = yes astropy_header_packages = numpy, pandas """) testdir.inline_run() elif method == 'ini_list': testdir.makeini(""" [pytest] astropy_header = yes astropy_header_packages = numpy pandas """) testdir.inline_run() elif method == 'conftest': testdir.makeconftest(""" def pytest_configure(config): config.option.astropy_header = True config.option.astropy_header_packages = ['numpy', 'pandas'] """) testdir.inline_run() out, err = capsys.readouterr() print(out) lines = extract_package_version_lines(out) assert len(lines) == 2 assert lines[0] == f'numpy: {NUMPY_VERSION}' assert lines[1].startswith('pandas') @pytest.mark.parametrize('method', ['cli', 'ini', 'ini_list', 'conftest']) def test_nonexistent(testdir, capsys, method): if method == 'cli': testdir.inline_run("--astropy-header", "--astropy-header-packages=apackagethatdoesnotexist") elif method == 'ini': testdir.makeini(""" [pytest] astropy_header = yes astropy_header_packages = apackagethatdoesnotexist """) testdir.inline_run() elif method == 'ini_list': testdir.makeini(""" [pytest] astropy_header = yes astropy_header_packages = apackagethatdoesnotexist """) testdir.inline_run() elif method == 'conftest': testdir.makeconftest(""" def pytest_configure(config): config.option.astropy_header = True config.option.astropy_header_packages = ['apackagethatdoesnotexist'] """) testdir.inline_run() out, err = capsys.readouterr() lines = extract_package_version_lines(out) assert len(lines) == 1 assert lines[0] == 'apackagethatdoesnotexist: not available' def test_modify_in_conftest(testdir, capsys): testdir.makeconftest(""" 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') PYTEST_HEADER_MODULES['scikit-image'] = 'skimage' TESTED_VERSIONS['fakepackage'] = '1.0.2' """) testdir.inline_run() out, err = capsys.readouterr() assert err == '' lines = extract_package_version_lines(out) assert len(lines) == 5 assert lines[0].startswith('Numpy: ') assert lines[1].startswith('Scipy: ') assert lines[2].startswith('Matplotlib: ') assert lines[3].startswith('h5py: ') assert lines[4].startswith('scikit-image: ') assert 'Running tests with fakepackage version 1.0.2' in out ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1662497026.0 pytest-astropy-header-0.2.2/tox.ini0000644000175100001710000000133714305730402016704 0ustar00runnerdocker[tox] envlist = py{37,38,39,310}-test{,-devdeps} codestyle requires = setuptools >= 30.3.0 pip >= 19.3.1 isolated_build = true [testenv] changedir = .tmp/{envname} description = run tests extras = test deps = pytest46: pytest==4.6.* pytest50: pytest==5.0.* pytest51: pytest==5.1.* pytest52: pytest==5.2.* pytest53: pytest==5.3.* pytest60: pytest==6.0.* pytest61: pytest==6.1.* pytest62: pytest==6.2.* pytestdev: git+https://github.com/pytest-dev/pytest#egg=pytest commands = pip freeze pytest {toxinidir}/tests {posargs} [testenv:codestyle] skip_install = true description = check code style, e.g. with flake8 deps = flake8 commands = flake8 pytest_astropy_header --count