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!
{%- 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 }} |
|
|
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 %}
No.
In Python 3.12+, you can use the functions provided by
importlib.resources
to access both files and directories from your resource folders.
In Python 3.7-3.11, you could use them to at least access files, while for
entire directories you had to use the (discouraged)
pkg_resources ResourceManager
API
API (part of setuptools).
By now, the only purpose of these plugins, at least as far as this comparison is concerned, is to get rid of the boilerplate for you.
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.