Skip to main content

A pytest plugin to detect unused files

Project description

pytest-filecov

Overview

This is a pytest plugin to monitor file accesses while tests are running, then output a report listing files along with whether or not they were accessed:

$ py.test --filecov tests
============================= test session starts ==============================
platform linux -- Python 3.9.5, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
filecov: tests
rootdir: /home/rohan/src/pytest-filecov
plugins: cov-2.12.1, filecov-0.1.0
collected 3 items

tests/test_plugin.py ...                                                 [100%]

============================ pytest-filecov report =============================
Filename                 Covered?
--------                 --------
tests/__init__.py        0
tests/fakecmd.py         1
tests/test_plugin.py     1
tests/some-file          1
tests/other-file         0
============================== 3 passed in 0.13s ===============================

Usage

Prerequisites:

  • Linux
  • inotifywait (try installing inotify-tools package)

Install the plugin:

pip install pytest-filecov

When running your test suite, add --filecov <path> specifying the directory tree(s) for which you'd like a report:

py.test --filecov somedir

Why?

This plugin targets the following scenario:

  • You've got a large, complex test suite.
  • You've got some tests relying on external data stored in files.
  • After some refactors, you expect some of the test data files are now unused and you'd like to clean them up, but you have no reliable way to determine what is or is not used.

Just as pytest-cov can help you seek and destroy dead Python code after refactors, pytest-filecov can do the same for dead/unused data files.

Caveats and missing features

This plugin is rudimentary, with many missing features.

  • The format of the reporter is not configurable.
  • The list of files included in the report comes from git ls-files and this is not configurable.
  • .py files may commonly be listed as uncovered for various reasons (e.g. .pyc files were used; or files were imported before monitoring began)

Contributions to improve any of the above are welcome.

License

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest-filecov-0.1.0.linux-x86_64.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_filecov-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file pytest-filecov-0.1.0.linux-x86_64.tar.gz.

File metadata

  • Download URL: pytest-filecov-0.1.0.linux-x86_64.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for pytest-filecov-0.1.0.linux-x86_64.tar.gz
Algorithm Hash digest
SHA256 9162425c8e15f2fdaf260bb61407a4eba9c930f02166c71bdc06056d45c8cade
MD5 8ff9dce18bc656a5b65baa636739dda7
BLAKE2b-256 36692a8ff054031de7bc00bacd04374e064318aa76bf6ab759045179252e31b2

See more details on using hashes here.

File details

Details for the file pytest_filecov-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_filecov-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5

File hashes

Hashes for pytest_filecov-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0cc03051177d9b524e8c384cfebe8f843e083b81523bfa4b8d008660b3a34b6a
MD5 b644282982b61c7123bf043928590e69
BLAKE2b-256 da765fb70fb3af0e2f036003a495a4dd0027388034d9f99e1791002d991bb73e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page