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