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

Pytest plugin to check for files left open at the end of a test run

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

Science Score: 46.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    5 of 34 committers (14.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.8%) to scientific vocabulary

Keywords from Contributors

astronomy astropy astrophysics closember astropy-affiliated jwst gtk qt tk wx
Last synced: 7 months ago · JSON representation

Repository

Pytest plugin to check for files left open at the end of a test run

Basic Info
  • Host: GitHub
  • Owner: astropy
  • License: bsd-3-clause
  • Language: Python
  • Default Branch: main
  • Size: 576 KB
Statistics
  • Stars: 9
  • Watchers: 17
  • Forks: 10
  • Open Issues: 0
  • Releases: 1
Archived
Created over 8 years ago · Last pushed almost 2 years ago
Metadata Files
Readme Changelog License

README.rst

================
pytest-openfiles
================

.. image:: https://zenodo.org/badge/104253678.svg
  :target: https://zenodo.org/doi/10.5281/zenodo.11494706

**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.

Owner

  • Name: The Astropy Project
  • Login: astropy
  • Kind: organization

GitHub Events

Total
  • Watch event: 1
  • Fork event: 1
Last Year
  • Watch event: 1
  • Fork event: 1

Committers

Last synced: 9 months ago

All Time
  • Total Commits: 532
  • Total Committers: 34
  • Avg Commits per committer: 15.647
  • Development Distribution Score (DDS): 0.788
Past Year
  • Commits: 3
  • Committers: 1
  • Avg Commits per committer: 3.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Thomas Robitaille t****e@g****m 113
Michael Droettboom m****m@g****m 110
Erik M. Bray e****y@s****u 82
Dan D'Avella d****a@s****u 39
Matt Davis j****c@g****m 36
Erik Tollerud e****d@g****m 28
Dan D'Avella d****a@g****m 15
Stuart Mumford s****t@c****m 15
Brigitta Sipocz b****z@g****m 15
P. L. Lim 2****m 14
Adam Ginsburg (keflavich) k****h@g****m 10
Marten van Kerkwijk m****k@a****a 7
Pey Lian Lim l****m@s****u 7
Joseph Jon Booker j****e@n****t 6
Michael Seifert m****4@y****e 5
Erik Bray e****y@g****m 4
Simon Conseil c****t@s****g 4
Christoph Deil D****h@g****m 3
ktchrn k****v@p****u 3
Curtis McCully c****y@l****t 2
Adrian Price-Whelan a****w@g****m 1
Todd t****8@g****m 1
Orion Poplawski o****n@c****m 1
Bruno Oliveira n****s@g****m 1
Daniel Hahler g****t@t****e 1
Derek Homeier d****e@g****e 1
Julien Woillez j****z@g****m 1
Larry Bradley l****y@g****m 1
Matteo Bachetti m****o@m****t 1
Ole Streicher d****n@l****x 1
and 4 more...

Issues and Pull Requests

Last synced: 7 months ago

All Time
  • Total issues: 22
  • Total pull requests: 26
  • Average time to close issues: over 1 year
  • Average time to close pull requests: about 1 month
  • Total issue authors: 11
  • Total pull request authors: 8
  • Average comments per issue: 2.27
  • Average comments per pull request: 1.42
  • Merged pull requests: 23
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • pllim (11)
  • astrofrog (2)
  • mcallaghan-bsm (1)
  • mhvk (1)
  • stscieisenhamer (1)
  • hamogu (1)
  • saimn (1)
  • seifertm (1)
  • MiguelLatorre (1)
  • drdavella (1)
  • costrouc (1)
Pull Request Authors
  • drdavella (9)
  • astrofrog (6)
  • pllim (5)
  • bsipocz (2)
  • scarabeusiv (1)
  • toddrme2178 (1)
  • blueyed (1)
  • saimn (1)
Top Labels
Issue Labels
bug (2) enhancement (2) question (1)
Pull Request Labels
bug (3) enhancement (2) docs (2) Build wheels (1) merge-when-ci-passes (1)

Packages

  • Total packages: 4
  • Total downloads:
    • pypi 34,143 last-month
  • Total docker downloads: 13,249
  • Total dependent packages: 37
    (may contain duplicates)
  • Total dependent repositories: 3,606
    (may contain duplicates)
  • Total versions: 20
  • Total maintainers: 4
pypi.org: pytest-openfiles

Pytest plugin for detecting inadvertent open file handles

  • Versions: 8
  • Dependent Packages: 28
  • Dependent Repositories: 3,424
  • Downloads: 34,143 Last month
  • Docker Downloads: 13,249
Rankings
Dependent repos count: 0.2%
Dependent packages count: 0.4%
Downloads: 1.0%
Docker downloads count: 1.1%
Average: 5.8%
Forks count: 11.4%
Stargazers count: 20.3%
Maintainers (3)
Last synced: 7 months ago
spack.io: py-pytest-openfiles

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

  • Versions: 1
  • Dependent Packages: 1
  • Dependent Repositories: 0
Rankings
Dependent repos count: 0.0%
Forks count: 24.0%
Average: 27.4%
Stargazers count: 28.5%
Dependent packages count: 57.3%
Maintainers (1)
Last synced: 7 months ago
conda-forge.org: pytest-openfiles

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.

  • Versions: 5
  • Dependent Packages: 7
  • Dependent Repositories: 91
Rankings
Dependent repos count: 3.6%
Dependent packages count: 8.0%
Average: 29.0%
Forks count: 46.1%
Stargazers count: 58.3%
Last synced: 7 months ago
anaconda.org: pytest-openfiles

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.

  • Versions: 6
  • Dependent Packages: 1
  • Dependent Repositories: 91
Rankings
Dependent repos count: 19.4%
Dependent packages count: 30.7%
Average: 39.6%
Forks count: 52.5%
Stargazers count: 55.7%
Last synced: 8 months ago

Dependencies

.github/workflows/ci_workflows.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
.github/workflows/publish.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • pypa/gh-action-pypi-publish release/v1 composite
pyproject.toml pypi
setup.py pypi