././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6876545 pytest_openfiles-0.6.0/0000755000175100001770000000000000000000000015717 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6836545 pytest_openfiles-0.6.0/.github/0000755000175100001770000000000000000000000017257 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6836545 pytest_openfiles-0.6.0/.github/workflows/0000755000175100001770000000000000000000000021314 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/.github/workflows/ci_workflows.yml0000644000175100001770000000256600000000000024560 0ustar00runnerdocker00000000000000name: CI on: pull_request: push: schedule: # Run every Sunday at 04:53 UTC - cron: 53 4 * * 0 jobs: tests: runs-on: ${{ matrix.os }} strategy: fail-fast: false 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: ubuntu-latest python-version: 3.9 toxenv: py39-test-pytest62 - os: macos-latest python-version: '3.10' toxenv: py310-test-pytest72 - os: ubuntu-latest python-version: '3.11' toxenv: py311-test-pytestdev steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v4 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=1717622056.0 pytest_openfiles-0.6.0/.github/workflows/publish.yml0000644000175100001770000000232400000000000023506 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@v3 with: fetch-depth: 0 - uses: actions/setup-python@v4 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 long_description run: python -m twine check --strict dist/* - name: Test package run: | cd .. python -m venv testenv testenv/bin/pip install pytest pytest-openfiles/dist/*.whl testenv/bin/pytest pytest-openfiles/tests --open-files - 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_password }} ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/.gitignore0000644000175100001770000000116300000000000017710 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 # 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 # Generated by Pytest v .pytest_cache # Mac OSX .DS_Store # PyCharm .idea pytest_openfiles/version.py ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/CHANGES.rst0000644000175100001770000000200100000000000017512 0ustar00runnerdocker000000000000000.6.0 (2024-06-05) ================== - Replaced ``distutils`` with ``packaging``; the latter now a required dependency. [#43] - Dropped support for Python 3.6. [#46] 0.5.0 (2020-04-16) ================== - Updated package infrastructure. [#29] - Force garbage collection before checking for open files. [#30] 0.4.0 (2019-07-20) ================== - Added the ability to use ``*`` and ``?`` wildcards in ``open_files_ignore``. [#22] - Fixed compatibility with pytest 4.2. [#20] 0.3.2 (2019-01-07) ================== - Replace deprecated method to allow for compatibility with ``pytest-4.1`` and later. [#19] 0.3.1 (2018-11-26) ================== - Fix a minor packaging issue. [#13] 0.3.0 (2018-04-20) ================== - Add decorator to skip detection of open files for particular tests. [#10] - Fix packaging error: do not include tests in package distribution. [#11] 0.2 (2017-12-07) ================ - Remove test dependency on astropy. [#4] 0.1 (2017-10-09) ================ - Alpha release. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/LICENSE.rst0000644000175100001770000000273000000000000017535 0ustar00runnerdocker00000000000000Copyright (c) 2011-2017, 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=1717622056.0 pytest_openfiles-0.6.0/MANIFEST.in0000644000175100001770000000023100000000000017451 0ustar00runnerdocker00000000000000include LICENSE.rst include README.rst include CHANGES.rst include setup.cfg include pyproject.toml recursive-include tests * global-exclude *.pyc *.o ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6876545 pytest_openfiles-0.6.0/PKG-INFO0000644000175100001770000001304200000000000017014 0ustar00runnerdocker00000000000000Metadata-Version: 2.1 Name: pytest-openfiles Version: 0.6.0 Summary: Pytest plugin for detecting inadvertent open file handles Home-page: https://github.com/astropy/pytest-openfiles Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Keywords: detect,open,file,handle,psutil,pytest,py.test Classifier: Development Status :: 3 - Alpha Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 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: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=3.7 Description-Content-Type: text/x-rst License-File: LICENSE.rst Requires-Dist: packaging Requires-Dist: pytest>=4.6 Requires-Dist: psutil ================ pytest-openfiles ================ **IMPORTANT: 0.6.0 is the final release. This package is now archived and no longer being developed.** This package provides a plugin for the `pytest`_ framework that allows developers to detect whether any file handles or other file-like objects were inadvertently left open at the end of a unit test. It has been moved from the core `astropy`_ project since it is of use more generally. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ IMPORTANT: Retirement Roadmap ----------------------------- As of https://github.com/astropy/astropy/pull/14041 , this package is no longer used in ``astropy`` core library. We strongly advise any packages that still use this package to migrate away from it. When ``astropy`` 6.0 is released (tentatively Nov 2023), none of the active development branches of the core library would use this package anymore. After that, we will just do one last release of ``pytest-openfiles`` and archive this repository. To test for open files without this package, you can do this from the command line using the `-W option `_:: pytest -W error::ResourceWarning Alternately, you can also use `pytest configuration file `_. The following example is for ``setup.cfg``:: [tool:pytest] filterwarnings = error::ResourceWarning Also see https://docs.astropy.org/en/latest/development/testguide.html#testing-for-open-files on how to test for open files without this package when contributing to ``astropy``. Motivation ---------- The `pytest-openfiles`_ plugin allows for the detection of open I/O resources at the end of unit tests. This is particularly useful for testing code that manipulates file handles or other I/O resources. It allows developers to ensure that this kind of code properly cleans up I/O resources when they are no longer needed. Installation ------------ The ``pytest-openfiles`` plugin can be installed using ``pip``:: $ pip install pytest-openfiles It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-openfiles $ cd pytest-openfiles $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- This plugin adds the ``--open-files`` option to the ``pytest`` command. When running tests with ``--open-files``, if a file is opened during the course of a unit test but that file is not closed before the test finishes, the test will fail. In some cases certain files are expected to remain open between tests. In order to prevent these files from causing tests to fail, they can be ignored using the configuration file variable ``open_files_ignore``. This variable is added to the ``[tool:pytest]`` section of a package's top-level ``setup.cfg`` file. Files can be ignored using a fully specified filename:: [tool:pytest] open_files_ignore = "/home/user/monty/output.log" It is also possible to ignore files with a particular name regardless of where they reside in the file system:: [tool:pytest] open_files_ignore = "output.log" In this example, all files named ``output.log`` will be ignored if they are found to remain open after a test completes. Paths and filenames can include ``*`` and ``?`` as wildcards:: [tool:pytest] open_files_ignore = "*.ttf" It is also possible to ignore open files for particular test cases by decorating them with the ``openfiles_ignore`` decorator: .. code:: import pytest @pytest.mark.openfiles_ignore def test_open_file_and_ignore(): """We want to ignore this test when checking for open file handles.""" The test function will not be skipped, but any files that are left open by the test will be ignored by this plugin. Development Status ------------------ .. image:: https://github.com/astropy/pytest-openfiles/workflows/CI/badge.svg :target: https://github.com/astropy/pytest-openfiles/actions :alt: CI Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-openfiles License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/README.rst0000644000175100001770000001047500000000000017415 0ustar00runnerdocker00000000000000================ pytest-openfiles ================ **IMPORTANT: 0.6.0 is the final release. This package is now archived and no longer being developed.** This package provides a plugin for the `pytest`_ framework that allows developers to detect whether any file handles or other file-like objects were inadvertently left open at the end of a unit test. It has been moved from the core `astropy`_ project since it is of use more generally. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ IMPORTANT: Retirement Roadmap ----------------------------- As of https://github.com/astropy/astropy/pull/14041 , this package is no longer used in ``astropy`` core library. We strongly advise any packages that still use this package to migrate away from it. When ``astropy`` 6.0 is released (tentatively Nov 2023), none of the active development branches of the core library would use this package anymore. After that, we will just do one last release of ``pytest-openfiles`` and archive this repository. To test for open files without this package, you can do this from the command line using the `-W option `_:: pytest -W error::ResourceWarning Alternately, you can also use `pytest configuration file `_. The following example is for ``setup.cfg``:: [tool:pytest] filterwarnings = error::ResourceWarning Also see https://docs.astropy.org/en/latest/development/testguide.html#testing-for-open-files on how to test for open files without this package when contributing to ``astropy``. Motivation ---------- The `pytest-openfiles`_ plugin allows for the detection of open I/O resources at the end of unit tests. This is particularly useful for testing code that manipulates file handles or other I/O resources. It allows developers to ensure that this kind of code properly cleans up I/O resources when they are no longer needed. Installation ------------ The ``pytest-openfiles`` plugin can be installed using ``pip``:: $ pip install pytest-openfiles It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-openfiles $ cd pytest-openfiles $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- This plugin adds the ``--open-files`` option to the ``pytest`` command. When running tests with ``--open-files``, if a file is opened during the course of a unit test but that file is not closed before the test finishes, the test will fail. In some cases certain files are expected to remain open between tests. In order to prevent these files from causing tests to fail, they can be ignored using the configuration file variable ``open_files_ignore``. This variable is added to the ``[tool:pytest]`` section of a package's top-level ``setup.cfg`` file. Files can be ignored using a fully specified filename:: [tool:pytest] open_files_ignore = "/home/user/monty/output.log" It is also possible to ignore files with a particular name regardless of where they reside in the file system:: [tool:pytest] open_files_ignore = "output.log" In this example, all files named ``output.log`` will be ignored if they are found to remain open after a test completes. Paths and filenames can include ``*`` and ``?`` as wildcards:: [tool:pytest] open_files_ignore = "*.ttf" It is also possible to ignore open files for particular test cases by decorating them with the ``openfiles_ignore`` decorator: .. code:: import pytest @pytest.mark.openfiles_ignore def test_open_file_and_ignore(): """We want to ignore this test when checking for open file handles.""" The test function will not be skipped, but any files that are left open by the test will be ignored by this plugin. Development Status ------------------ .. image:: https://github.com/astropy/pytest-openfiles/workflows/CI/badge.svg :target: https://github.com/astropy/pytest-openfiles/actions :alt: CI Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-openfiles License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/pyproject.toml0000644000175100001770000000021400000000000020630 0ustar00runnerdocker00000000000000[build-system] requires = ["setuptools>=30.3.0", "setuptools_scm", "wheel"] build-backend = 'setuptools.build_meta' ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6876545 pytest_openfiles-0.6.0/pytest_openfiles/0000755000175100001770000000000000000000000021313 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/pytest_openfiles/__init__.py0000644000175100001770000000030300000000000023420 0ustar00runnerdocker00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This package contains pytest plugins that are used by the astropy test suite. """ from .version import version as __version__ ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/pytest_openfiles/plugin.py0000644000175100001770000001052600000000000023167 0ustar00runnerdocker00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst """ This plugin provides support for testing whether file-like objects are properly closed. """ import os import gc import fnmatch from packaging.version import Version import pytest try: import importlib.machinery as importlib_machinery except ImportError: import imp importlib_machinery = None _pytest_36 = Version(pytest.__version__) >= Version("3.6") def pytest_addoption(parser): parser.addoption("--open-files", action="store_true", help="fail if any test leaves files open") parser.addini("open_files_ignore", "when used with the --open-files option, allows " "specifying names of files that may be ignored when " "left open between tests--files in this list are matched " "may be specified by their base name (ignoring their full " "path) or by absolute path", type="args", default=()) def pytest_configure(config): config.getini('markers').append( 'openfiles_ignore: Indicate that open files should be ignored for this test') # Open file detection. # # This works by calling out to psutil to get the list of open files # held by the process both before and after the test. If something is # still open after the test that wasn't open before the test, an # AssertionError is raised. # # This is not thread-safe. We're not currently running our tests # multi-threaded, but that is worth noting. def _get_open_file_list(): import psutil files = [] p = psutil.Process() if importlib_machinery is not None: suffixes = tuple(importlib_machinery.all_suffixes()) else: suffixes = tuple(info[0] for info in imp.get_suffixes()) files = [x.path for x in p.open_files() if not x.path.endswith(suffixes)] return set(files) def pytest_runtest_setup(item): # Store a list of the currently opened files so we can compare # against them when the test is done. if item.config.getvalue('open_files'): # Retain backwards compatibility with earlier versions of pytest if _pytest_36: ignore = item.get_closest_marker('openfiles_ignore') else: ignore = item.get_marker('openfiles_ignore') if not ignore: item.open_files = _get_open_file_list() def pytest_runtest_teardown(item, nextitem): # a "skipped" test will not have been called with # pytest_runtest_setup, so therefore won't have an # "open_files" member if (not item.config.getvalue('open_files') or not hasattr(item, 'open_files')): return start_open_files = item.open_files del item.open_files # We now force garbage collection - we need to do this because e.g. in cases # where a memory mapped array was opened in the test and then goes out of # scope at the end of the test, the original file may still be open but # can be properly closed by forcing gc.collect(). This was found to be # needed for astropy.io.fits under certain circumstances. gc.collect() open_files = _get_open_file_list() # This works in tandem with the test_open_file_detection test to # ensure that it creates one extra open file. if item.name == 'test_open_file_detection': assert len(start_open_files) + 1 == len(open_files) return not_closed = set() open_files_ignore = item.config.getini('open_files_ignore') for filename in open_files: ignore = False for ignored in open_files_ignore: # Note that we use fnmatch rather than re for simplicity since # we are dealing with file paths - fnmatch works with the standard # * and ? wildcards in paths. if not os.path.isabs(ignored): # Since the path is not absolute, we convert it to # */ to make sure it matches absolute paths. ignored = os.path.join('*', ignored) if fnmatch.fnmatch(filename, ignored): ignore = True break if ignore: continue if filename not in start_open_files: not_closed.add(filename) if len(not_closed): msg = ['File(s) not closed:'] for name in not_closed: msg.append(' {0}'.format(name)) raise AssertionError('\n'.join(msg)) ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles/version.py0000644000175100001770000000063300000000000023354 0ustar00runnerdocker00000000000000# file generated by setuptools_scm # don't change, don't track in version control TYPE_CHECKING = False if TYPE_CHECKING: from typing import Tuple, Union VERSION_TUPLE = Tuple[Union[int, str], ...] else: VERSION_TUPLE = object version: str __version__: str __version_tuple__: VERSION_TUPLE version_tuple: VERSION_TUPLE __version__ = version = '0.6.0' __version_tuple__ = version_tuple = (0, 6, 0) ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6876545 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/0000755000175100001770000000000000000000000023005 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/PKG-INFO0000644000175100001770000001304200000000000024102 0ustar00runnerdocker00000000000000Metadata-Version: 2.1 Name: pytest-openfiles Version: 0.6.0 Summary: Pytest plugin for detecting inadvertent open file handles Home-page: https://github.com/astropy/pytest-openfiles Author: The Astropy Developers Author-email: astropy.team@gmail.com License: BSD Keywords: detect,open,file,handle,psutil,pytest,py.test Classifier: Development Status :: 3 - Alpha Classifier: Framework :: Pytest Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 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: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Topic :: Software Development :: Testing Classifier: Topic :: Utilities Requires-Python: >=3.7 Description-Content-Type: text/x-rst License-File: LICENSE.rst Requires-Dist: packaging Requires-Dist: pytest>=4.6 Requires-Dist: psutil ================ pytest-openfiles ================ **IMPORTANT: 0.6.0 is the final release. This package is now archived and no longer being developed.** This package provides a plugin for the `pytest`_ framework that allows developers to detect whether any file handles or other file-like objects were inadvertently left open at the end of a unit test. It has been moved from the core `astropy`_ project since it is of use more generally. .. _pytest: https://pytest.org/en/latest/ .. _astropy: https://astropy.org/en/latest/ IMPORTANT: Retirement Roadmap ----------------------------- As of https://github.com/astropy/astropy/pull/14041 , this package is no longer used in ``astropy`` core library. We strongly advise any packages that still use this package to migrate away from it. When ``astropy`` 6.0 is released (tentatively Nov 2023), none of the active development branches of the core library would use this package anymore. After that, we will just do one last release of ``pytest-openfiles`` and archive this repository. To test for open files without this package, you can do this from the command line using the `-W option `_:: pytest -W error::ResourceWarning Alternately, you can also use `pytest configuration file `_. The following example is for ``setup.cfg``:: [tool:pytest] filterwarnings = error::ResourceWarning Also see https://docs.astropy.org/en/latest/development/testguide.html#testing-for-open-files on how to test for open files without this package when contributing to ``astropy``. Motivation ---------- The `pytest-openfiles`_ plugin allows for the detection of open I/O resources at the end of unit tests. This is particularly useful for testing code that manipulates file handles or other I/O resources. It allows developers to ensure that this kind of code properly cleans up I/O resources when they are no longer needed. Installation ------------ The ``pytest-openfiles`` plugin can be installed using ``pip``:: $ pip install pytest-openfiles It is also possible to install the latest development version from the source repository:: $ git clone https://github.com/astropy/pytest-openfiles $ cd pytest-openfiles $ python ./setup.py install In either case, the plugin will automatically be registered for use with ``pytest``. Usage ----- This plugin adds the ``--open-files`` option to the ``pytest`` command. When running tests with ``--open-files``, if a file is opened during the course of a unit test but that file is not closed before the test finishes, the test will fail. In some cases certain files are expected to remain open between tests. In order to prevent these files from causing tests to fail, they can be ignored using the configuration file variable ``open_files_ignore``. This variable is added to the ``[tool:pytest]`` section of a package's top-level ``setup.cfg`` file. Files can be ignored using a fully specified filename:: [tool:pytest] open_files_ignore = "/home/user/monty/output.log" It is also possible to ignore files with a particular name regardless of where they reside in the file system:: [tool:pytest] open_files_ignore = "output.log" In this example, all files named ``output.log`` will be ignored if they are found to remain open after a test completes. Paths and filenames can include ``*`` and ``?`` as wildcards:: [tool:pytest] open_files_ignore = "*.ttf" It is also possible to ignore open files for particular test cases by decorating them with the ``openfiles_ignore`` decorator: .. code:: import pytest @pytest.mark.openfiles_ignore def test_open_file_and_ignore(): """We want to ignore this test when checking for open file handles.""" The test function will not be skipped, but any files that are left open by the test will be ignored by this plugin. Development Status ------------------ .. image:: https://github.com/astropy/pytest-openfiles/workflows/CI/badge.svg :target: https://github.com/astropy/pytest-openfiles/actions :alt: CI Status Questions, bug reports, and feature requests can be submitted on `github`_. .. _github: https://github.com/astropy/pytest-openfiles License ------- This plugin is licensed under a 3-clause BSD style license - see the ``LICENSE.rst`` file. ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/SOURCES.txt0000644000175100001770000000115000000000000024666 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_openfiles/__init__.py pytest_openfiles/plugin.py pytest_openfiles/version.py pytest_openfiles.egg-info/PKG-INFO pytest_openfiles.egg-info/SOURCES.txt pytest_openfiles.egg-info/dependency_links.txt pytest_openfiles.egg-info/entry_points.txt pytest_openfiles.egg-info/not-zip-safe pytest_openfiles.egg-info/requires.txt pytest_openfiles.egg-info/top_level.txt tests/__init__.py tests/test_open_file_detection.py tests/data/open_file_detection.txt././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/dependency_links.txt0000644000175100001770000000000100000000000027053 0ustar00runnerdocker00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/entry_points.txt0000644000175100001770000000006600000000000026305 0ustar00runnerdocker00000000000000[pytest11] pytest_openfiles = pytest_openfiles.plugin ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/not-zip-safe0000644000175100001770000000000100000000000025233 0ustar00runnerdocker00000000000000 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/requires.txt0000644000175100001770000000003500000000000025403 0ustar00runnerdocker00000000000000packaging pytest>=4.6 psutil ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622065.0 pytest_openfiles-0.6.0/pytest_openfiles.egg-info/top_level.txt0000644000175100001770000000002100000000000025530 0ustar00runnerdocker00000000000000pytest_openfiles ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6876545 pytest_openfiles-0.6.0/setup.cfg0000644000175100001770000000256200000000000017545 0ustar00runnerdocker00000000000000[metadata] name = pytest-openfiles url = https://github.com/astropy/pytest-openfiles author = The Astropy Developers author_email = astropy.team@gmail.com classifiers = Development Status :: 3 - Alpha Framework :: Pytest Intended Audience :: Developers License :: OSI Approved :: BSD License Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3 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 Programming Language :: Python :: 3.11 Programming Language :: Python :: Implementation :: CPython Topic :: Software Development :: Testing Topic :: Utilities license = BSD description = Pytest plugin for detecting inadvertent open file handles long_description = file: README.rst long_description_content_type = text/x-rst keywords = detect, open, file, handle, psutil, pytest, py.test [options] zip_safe = False packages = find: python_requires = >=3.7 setup_requires = setuptools_scm install_requires = packaging pytest>=4.6 psutil [options.entry_points] pytest11 = pytest_openfiles = pytest_openfiles.plugin [options.packages.find] exclude = tests [tool:pytest] minversion = 4.6 testpaths = tests [flake8] max-line-length = 100 [egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/setup.py0000755000175100001770000000022300000000000017431 0ustar00runnerdocker00000000000000#!/usr/bin/env python import os from setuptools import setup setup(use_scm_version={'write_to': os.path.join('pytest_openfiles', 'version.py')}) ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6876545 pytest_openfiles-0.6.0/tests/0000755000175100001770000000000000000000000017061 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/tests/__init__.py0000644000175100001770000000010000000000000021161 0ustar00runnerdocker00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst ././@PaxHeader0000000000000000000000000000003400000000000011452 xustar000000000000000028 mtime=1717622065.6876545 pytest_openfiles-0.6.0/tests/data/0000755000175100001770000000000000000000000017772 5ustar00runnerdocker00000000000000././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/tests/data/open_file_detection.txt0000644000175100001770000000001100000000000024521 0ustar00runnerdocker00000000000000CONTENTS ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/tests/test_open_file_detection.py0000644000175100001770000000073700000000000024477 0ustar00runnerdocker00000000000000# Licensed under a 3-clause BSD style license - see LICENSE.rst import os import pytest PKG_DATA_DIR = os.path.dirname(__file__) fd = None def test_open_file_detection(): global fd fd = open(os.path.join(PKG_DATA_DIR, 'data/open_file_detection.txt')) @pytest.mark.openfiles_ignore def test_skip_open_file_detection(): global fd fd = open(os.path.join(PKG_DATA_DIR, 'data/open_file_detection.txt')) def teardown(): if fd is not None: fd.close() ././@PaxHeader0000000000000000000000000000002600000000000011453 xustar000000000000000022 mtime=1717622056.0 pytest_openfiles-0.6.0/tox.ini0000644000175100001770000000135000000000000017231 0ustar00runnerdocker00000000000000[tox] envlist = py{37,38,39,310,311}-test{,-devdeps} codestyle requires = setuptools >= 30.3.0 pip >= 19.3.1 isolated_build = true [testenv] changedir = .tmp/{envname} description = run tests deps = pytest46: pytest==4.6.* pytest50: pytest==5.0.* pytest51: pytest==5.1.* pytest52: pytest==5.2.* pytest53: pytest==5.3.* pytest62: pytest==6.2.* pytest72: pytest==7.2.* pytestdev: git+https://github.com/pytest-dev/pytest#egg=pytest commands = pip freeze pytest {toxinidir}/tests {posargs} pytest --open-files {toxinidir}/tests {posargs} [testenv:codestyle] skip_install = true description = check code style, e.g. with flake8 deps = flake8 commands = flake8 pytest_openfiles --count