pytest-openfiles


Namepytest-openfiles JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://github.com/astropy/pytest-openfiles
SummaryPytest plugin for detecting inadvertent open file handles
upload_time2024-06-05 21:14:37
maintainerNone
docs_urlNone
authorThe Astropy Developers
requires_python>=3.7
licenseBSD
keywords detect open file handle psutil pytest py.test
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ================
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 <https://docs.python.org/3/using/cmdline.html#cmdoption-W>`_::

    pytest -W error::ResourceWarning

Alternately, you can also use
`pytest configuration file <https://docs.pytest.org/en/stable/reference/customize.html>`_.
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.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/astropy/pytest-openfiles",
    "name": "pytest-openfiles",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "detect, open, file, handle, psutil, pytest, py.test",
    "author": "The Astropy Developers",
    "author_email": "astropy.team@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/6c/c2/2f07cebdebfd53d11476ff77cfb3b709d16860dc1b2aac4903bb8ee0affe/pytest_openfiles-0.6.0.tar.gz",
    "platform": null,
    "description": "================\npytest-openfiles\n================\n\n**IMPORTANT: 0.6.0 is the final release. This package is now archived and no longer being developed.**\n\nThis package provides a plugin for the `pytest`_ framework that allows\ndevelopers to detect whether any file handles or other file-like objects were\ninadvertently left open at the end of a unit test. It has been moved from the\ncore `astropy`_ project since it is of use more generally.\n\n.. _pytest: https://pytest.org/en/latest/\n.. _astropy: https://astropy.org/en/latest/\n\nIMPORTANT: Retirement Roadmap\n-----------------------------\n\nAs of https://github.com/astropy/astropy/pull/14041 , this package is no\nlonger used in ``astropy`` core library. We strongly advise any packages\nthat still use this package to migrate away from it. When ``astropy`` 6.0\nis released (tentatively Nov 2023), none of the active development branches\nof the core library would use this package anymore.\n\nAfter that, we will just do one last release of ``pytest-openfiles``\nand archive this repository.\n\nTo test for open files without this package, you can do this from the\ncommand line using the\n`-W option <https://docs.python.org/3/using/cmdline.html#cmdoption-W>`_::\n\n    pytest -W error::ResourceWarning\n\nAlternately, you can also use\n`pytest configuration file <https://docs.pytest.org/en/stable/reference/customize.html>`_.\nThe following example is for ``setup.cfg``::\n\n    [tool:pytest]\n    filterwarnings =\n        error::ResourceWarning\n\nAlso see https://docs.astropy.org/en/latest/development/testguide.html#testing-for-open-files\non how to test for open files without this package when contributing to ``astropy``.\n\nMotivation\n----------\n\nThe `pytest-openfiles`_ plugin allows for the detection of open I/O resources\nat the end of unit tests.  This is particularly useful for testing code that\nmanipulates file handles or other I/O resources. It allows developers to ensure\nthat this kind of code properly cleans up I/O resources when they are no longer\nneeded.\n\nInstallation\n------------\n\nThe ``pytest-openfiles`` plugin can be installed using ``pip``::\n\n    $ pip install pytest-openfiles\n\nIt is also possible to install the latest development version from the source\nrepository::\n\n    $ git clone https://github.com/astropy/pytest-openfiles\n    $ cd pytest-openfiles\n    $ python ./setup.py install\n\nIn either case, the plugin will automatically be registered for use with\n``pytest``.\n\nUsage\n-----\n\nThis plugin adds the ``--open-files`` option to the ``pytest`` command.  When\nrunning tests with ``--open-files``, if a file is opened during the course of a\nunit test but that file is not closed before the test finishes, the test will\nfail.\n\nIn some cases certain files are expected to remain open between tests. In order\nto prevent these files from causing tests to fail, they can be ignored using\nthe configuration file variable ``open_files_ignore``. This variable is added\nto the ``[tool:pytest]`` section of a package's top-level ``setup.cfg`` file.\n\nFiles can be ignored using a fully specified filename::\n\n    [tool:pytest]\n    open_files_ignore = \"/home/user/monty/output.log\"\n\nIt is also possible to ignore files with a particular name regardless of where\nthey reside in the file system::\n\n    [tool:pytest]\n    open_files_ignore = \"output.log\"\n\nIn this example, all files named ``output.log`` will be ignored if they are\nfound to remain open after a test completes. Paths and filenames can include\n``*`` and ``?`` as wildcards::\n\n    [tool:pytest]\n    open_files_ignore = \"*.ttf\"\n\nIt is also possible to ignore open files for particular test cases by\ndecorating them with the ``openfiles_ignore`` decorator:\n\n.. code::\n\n    import pytest\n\n    @pytest.mark.openfiles_ignore\n    def test_open_file_and_ignore():\n        \"\"\"We want to ignore this test when checking for open file handles.\"\"\"\n\n\nThe test function will not be skipped, but any files that are left open by the\ntest will be ignored by this plugin.\n\n\nDevelopment Status\n------------------\n\n.. image:: https://github.com/astropy/pytest-openfiles/workflows/CI/badge.svg\n    :target: https://github.com/astropy/pytest-openfiles/actions\n    :alt: CI Status\n\nQuestions, bug reports, and feature requests can be submitted on `github`_.\n\n.. _github: https://github.com/astropy/pytest-openfiles\n\nLicense\n-------\nThis plugin is licensed under a 3-clause BSD style license - see the\n``LICENSE.rst`` file.\n",
    "bugtrack_url": null,
    "license": "BSD",
    "summary": "Pytest plugin for detecting inadvertent open file handles",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://github.com/astropy/pytest-openfiles"
    },
    "split_keywords": [
        "detect",
        " open",
        " file",
        " handle",
        " psutil",
        " pytest",
        " py.test"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "41b272489d6f61ab3c72d6ce41835b31f27fa79450c5cfbe943a7a75e0badffd",
                "md5": "ec3e7c065acb8c6d9ec4600feb434962",
                "sha256": "849b5b85644e31f2ce367c0fbbf53125b71a0a5d08500ddb08abcefc2dc3f99d"
            },
            "downloads": -1,
            "filename": "pytest_openfiles-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ec3e7c065acb8c6d9ec4600feb434962",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 7153,
            "upload_time": "2024-06-05T21:14:35",
            "upload_time_iso_8601": "2024-06-05T21:14:35.371834Z",
            "url": "https://files.pythonhosted.org/packages/41/b2/72489d6f61ab3c72d6ce41835b31f27fa79450c5cfbe943a7a75e0badffd/pytest_openfiles-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6cc22f07cebdebfd53d11476ff77cfb3b709d16860dc1b2aac4903bb8ee0affe",
                "md5": "2c225b9f2730540abb256af36b753ede",
                "sha256": "ff5160c34eaada82b983a2c316fcccb30e0094630e97784471f015956870a993"
            },
            "downloads": -1,
            "filename": "pytest_openfiles-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "2c225b9f2730540abb256af36b753ede",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 9012,
            "upload_time": "2024-06-05T21:14:37",
            "upload_time_iso_8601": "2024-06-05T21:14:37.119466Z",
            "url": "https://files.pythonhosted.org/packages/6c/c2/2f07cebdebfd53d11476ff77cfb3b709d16860dc1b2aac4903bb8ee0affe/pytest_openfiles-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-05 21:14:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "astropy",
    "github_project": "pytest-openfiles",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pytest-openfiles"
}
        
Elapsed time: 0.47651s