importorskip usage with "from" imports? #12894
-
I like that I can do things like this in a simple test, rather than use some janky setup code for ensuring that a runtime version and metadata version are single-sourced at build-time:
However, it relies on the fact that An example could be Something like this:
But, obviously, using the I just use If this is something that could be worth adding to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You could do: import importlib.metadata
import pytest
@pytest.mark.skipif(not hasattr(importlib.metadata, "packages_distributions"), reason="Needs packages_distributions")
def test_foo():
... = importlib.metadata.packages_distributions() and possibly even move that into a small helper if you want to have a nice |
Beta Was this translation helpful? Give feedback.
You could do:
and possibly even move that into a small helper if you want to have a nice
reason
without the duplication. That would have the additional benefit that the test gets skipped at collection time without having to first run it (and possibly set up fixtures) before finding out it's actually skipped.