A decorator designed to make testing optional dependencies painless.
Project description
A decorator designed to make testing optional dependencies painless.
It’s common for libraries to have optional dependencies where the code has to detect if they are installed, using a pattern like this:
try:
import something
else:
import something_else as something
That way something is always defined and the rest of the codebase does not need to care. But how do we test both branches under tests?
With fail_importing, you can just slap a decorator onto your test and the code being tested will act as if the dependency isn’t installed.
@fail_importing("something")
def test_something_else():
...
When the test finishes executing, the name can be imported as normal. It can be applied to normal functions, nested functions, relative imports, and even generators!
full_match is used to determine if the path matches or not, so you can use any regex matching you need. Note that relative imports are resolved to absolute imports before the check is made.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file fail_importing-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: fail_importing-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0a897472af8e7d015a32777dff0bf4f4a79d8666182ef5f07182f1357ccf252 |
|
MD5 | ee38e5a2344567ee4f94659e723657eb |
|
BLAKE2b-256 | a272f4b2f116a64a8ab2f4dc577b1fc0c6fca6edeeaa3309d326ba28bdf84d14 |