Search code examples
pythontestingtypeerrorpytestwand

Mute Pytest library output for imported library


I'm testing a function which uses Python Wand. When I test it with an invalid input it throws a BlobError which is a custom error from the Wand library. However, it seems that there's another TypeError happening within Wand at some point when I do so, which results in a big ugly Exception ignored in... error message under the Pytest results stdout.

I'm checking if Pytest raises the BlobError and that's fine, but I can't also check if it raises the TypeError, or just mute that message. So here's the Pytest test output:

================================ test session starts =================================
platform linux -- Python 3.5.2, pytest-3.2.5, py-1.5.2, pluggy-0.4.0
rootdir: /path/to/my/project/tests, inifile:
collected 1 item                                                                                                                              

test_split.py .

============================== 1 passed in 0.14 seconds ==============================
Exception ignored in: <bound method Resource.__del__ of <wand.image.Image: (empty)>>
Traceback (most recent call last):
  File "/my/comp/.local/share/virtualenvs/project-BRze6wfl/lib/python3.5/site-packages/wand/resource.py", line 232, in __del__
    self.destroy()
  File "/my/comp/.local/share/virtualenvs/project-BRze6wfl/lib/python3.5/site-packages/wand/image.py", line 2767, in destroy
    for i in range(0, len(self.sequence)):
TypeError: object of type 'NoneType' has no len()

And my test is simply:

with pytest.raises(wand.exceptions.BlobError):
        wand_split.split(PDF,TEMP, 260)

So the test is working the way I want, but how do I deal with the extra Wand TypeError?


Solution

  • That message indicates an exception raised inside __del__, doc says:

    Due to the precarious circumstances under which del() methods are invoked, exceptions that occur during their execution are ignored, and a warning is printed to sys.stderr instead. ...

    most likely, this happened when the python interpreter is exiting, to my knowledge, there is no simple way to mute this message with pytest.

    But with the line-no of traceback, I guess you are using a buggy version of wand, someone has reported a similar issue on github, you could try an upgrade and report issue back there.