././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3330731 pytest-astropy-header-0.2.0/0000755000175100001710000000000000000000000016566 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3330731 pytest-astropy-header-0.2.0/.github/0000755000175100001710000000000000000000000020126 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3330731 pytest-astropy-header-0.2.0/.github/workflows/0000755000175100001710000000000000000000000022163 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/.github/workflows/ci_workflows.yml0000644000175100001710000000273300000000000025423 0ustar00runnerdocker00000000000000name: CI on: pull_request: push: schedule: # Run every Sunday at 05:53 UTC - cron: 53 5 * * 0 jobs: tests: runs-on: ${{ matrix.os }} strategy: fail-fast: true matrix: include: - os: ubuntu-latest python-version: 3.7 toxenv: py37-test-pytest46 - os: windows-latest python-version: 3.7 toxenv: py37-test-pytest50 - os: macos-latest python-version: 3.8 toxenv: py38-test-pytest51 - os: ubuntu-latest python-version: 3.8 toxenv: py38-test-pytest52 - os: windows-latest python-version: 3.9 toxenv: py39-test-pytest53 - os: macos-latest python-version: 3.9 toxenv: py39-test-pytest60 - os: ubuntu-latest python-version: 3.9 toxenv: py39-test-pytest61 - os: windows-latest python-version: '3.10' toxenv: py310-test-pytest62 - os: ubuntu-latest python-version: '3.10' toxenv: py310-test-pytestdev steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install tox run: python -m pip install tox - name: Run tox run: tox -v -e ${{ matrix.toxenv }} ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/.github/workflows/publish.yml0000644000175100001710000000231700000000000024357 0ustar00runnerdocker00000000000000name: Release on: pull_request: push: tags: - '*' jobs: build-n-publish: name: Build and publish Python 🐍 distributions 📦 to PyPI runs-on: ubuntu-latest if: ((github.event_name == 'push' && startsWith(github.ref, 'refs/tags')) || contains(github.event.pull_request.labels.*.name, 'Build wheels')) steps: - uses: actions/checkout@v2 with: fetch-depth: 0 - uses: actions/setup-python@v2 with: python-version: 3.8 - name: Install python-build and twine run: python -m pip install pip build "twine>=3.3" -U - name: Build package run: python -m build --sdist --wheel . - name: List result run: ls -l dist - name: Check wheel run: python -m twine check --strict dist/* - name: Test package run: | cd .. python -m venv testenv testenv/bin/pip install astropy pytest pytest-astropy-header/dist/*.whl testenv/bin/pytest pytest-astropy-header/tests - name: Publish distribution 📦 to PyPI if: startsWith(github.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/.gitignore0000644000175100001710000000116300000000000020557 0ustar00runnerdocker00000000000000# 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 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/CHANGES.rst0000644000175100001710000000127300000000000020373 0ustar00runnerdocker000000000000000.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. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/LICENSE.rst0000644000175100001710000000272300000000000020406 0ustar00runnerdocker00000000000000Copyright (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. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/MANIFEST.in0000644000175100001710000000015000000000000020320 0ustar00runnerdocker00000000000000include LICENSE.rst include README.rst include CHANGES.rst include setup.cfg global-exclude *.pyc *.o ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3370733 pytest-astropy-header-0.2.0/PKG-INFO0000644000175100001710000002010300000000000017657 0ustar00runnerdocker00000000000000Metadata-Version: 2.1 Name: pytest-astropy-header Version: 0.2.0 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 Platform: UNKNOWN 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://img.shields.io/pypi/v/pytest-astropy-header.svg :target: https://pypi.python.org/pypi/pytest-astropy-header .. 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. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/README.rst0000644000175100001710000001632300000000000020262 0ustar00runnerdocker00000000000000===================== pytest-astropy-header ===================== .. image:: https://img.shields.io/pypi/v/pytest-astropy-header.svg :target: https://pypi.python.org/pypi/pytest-astropy-header .. 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. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/pyproject.toml0000644000175100001710000000021400000000000021477 0ustar00runnerdocker00000000000000[build-system] requires = ["setuptools>=30.3.0", "setuptools_scm", "wheel"] build-backend = 'setuptools.build_meta' ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3330731 pytest-astropy-header-0.2.0/pytest_astropy_header/0000755000175100001710000000000000000000000023207 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/pytest_astropy_header/__init__.py0000644000175100001710000000016500000000000025322 0ustar00runnerdocker00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst from .version import version as __version__ # noqa ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/pytest_astropy_header/display.py0000644000175100001710000001074600000000000025236 0ustar00runnerdocker00000000000000# 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 from collections import OrderedDict TESTED_VERSIONS = {} PYTEST_HEADER_MODULES = OrderedDict([('Numpy', 'numpy'), ('Scipy', 'scipy'), ('Matplotlib', 'matplotlib'), ('h5py', 'h5py'), ('Pandas', 'pandas')]) 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 = OrderedDict([(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 = OrderedDict([(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" special_opts = ["remote_data", "pep8"] opts = [] for op in special_opts: 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 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header/version.py0000644000175100001710000000021600000000000025245 0ustar00runnerdocker00000000000000# coding: utf-8 # file generated by setuptools_scm # don't change, don't track in version control version = '0.2.0' version_tuple = (0, 2, 0) ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3330731 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/0000755000175100001710000000000000000000000024701 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/PKG-INFO0000644000175100001710000002010300000000000025772 0ustar00runnerdocker00000000000000Metadata-Version: 2.1 Name: pytest-astropy-header Version: 0.2.0 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 Platform: UNKNOWN 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://img.shields.io/pypi/v/pytest-astropy-header.svg :target: https://pypi.python.org/pypi/pytest-astropy-header .. 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. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/SOURCES.txt0000644000175100001710000000113200000000000026562 0ustar00runnerdocker00000000000000.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././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/dependency_links.txt0000644000175100001710000000000100000000000030747 0ustar00runnerdocker00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/entry_points.txt0000644000175100001710000000010200000000000030170 0ustar00runnerdocker00000000000000[pytest11] pytest_astropy_header = pytest_astropy_header.display ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/not-zip-safe0000644000175100001710000000000100000000000027127 0ustar00runnerdocker00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/requires.txt0000644000175100001710000000004700000000000027302 0ustar00runnerdocker00000000000000pytest>=4.6 [test] numpy astropy>=4.0 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625736.0 pytest-astropy-header-0.2.0/pytest_astropy_header.egg-info/top_level.txt0000644000175100001710000000002600000000000027431 0ustar00runnerdocker00000000000000pytest_astropy_header ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3370733 pytest-astropy-header-0.2.0/setup.cfg0000644000175100001710000000206500000000000020412 0ustar00runnerdocker00000000000000[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 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/setup.py0000755000175100001710000000023000000000000020276 0ustar00runnerdocker00000000000000#!/usr/bin/env python import os from setuptools import setup setup(use_scm_version={'write_to': os.path.join('pytest_astropy_header', 'version.py')}) ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1640625736.3330731 pytest-astropy-header-0.2.0/tests/0000755000175100001710000000000000000000000017730 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/tests/test_display.py0000644000175100001710000001411300000000000023006 0ustar00runnerdocker00000000000000import 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 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1640625720.0 pytest-astropy-header-0.2.0/tox.ini0000644000175100001710000000133700000000000020105 0ustar00runnerdocker00000000000000[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