Skip to content

Latest commit

 

History

History
92 lines (73 loc) · 2.54 KB

README.template.md

File metadata and controls

92 lines (73 loc) · 2.54 KB

Comparison of pytest plugins for accessing data files

It is often said there are more pytest plugins that aim to provide convenient access to packaged data files than grains of sand on Earth. Here I compare them all.

Did I miss one or do you have suggestions for other criteria? Feel free to open an issue!

Comparison

{%- for plugin in plugins %} {%- endfor %}
Name / URL Supports copying to temp dir Supports access without copying Paths provided as Fixture names Folder names
{{ plugin.name }} {% if plugin.supports_copying_to_temp %}✔{% else %}❌{% endif %} {% if plugin.supports_access_without_copying %}✔{% else %}❌{% endif %} {{ plugin.provided_as }}
    {%- for fixture_name in plugin.fixture_names %}
  • {{ fixture_name }}
  • {%- endfor %}
    {%- for folder_name in plugin.folder_names %}
  • {{ folder_name }}
  • {%- endfor %}

Excluded

These plugins have names that might suggest they'd do something similar, but have slightly different aims than just providing convenient access to packaged data files:

{% for plugin in excluded_plugins -%}

  • [{{ plugin.name }}]({{ plugin.pypi_url }}): {{ plugin.reason|wordwrap(77)|indent(2) }} {% endfor %}

Do I even need a plugin for this?

No.

If you're only interested in files and not directories, in Python 3.7+ you can use the functions provided by importlib.resources.

The "older" method is to use pkg_resources's ResourceManager API (part of setuptools) which is discouraged but has the advantage that it also allows you to access entire directories.

The only purpose of these plugins, at least as far as this comparison is concerned, is to get rid of the boilerplate for you.

Other things to note

No matter which method or plugin you choose, all of them will have to extract data files if your package is stored in an archived form (e.g. egg or wheel). To avoid this, specify zip_safe=False in your package configuration.