diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index aca72ceb0d7..10d6fcde6ad 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -1,3 +1,4 @@ +import pytest import subprocess import sys @@ -36,23 +37,19 @@ def test_grab_x11(self): @unittest.skipIf(Image.core.HAVE_XCB, "tests missing XCB") def test_grab_no_xcb(self): if sys.platform not in ("win32", "darwin"): - with self.assertRaises(IOError) as e: + with pytest.raises(IOError) as e: ImageGrab.grab() - self.assertTrue( - str(e.exception).startswith("Pillow was built without XCB support") - ) + assert str(e.value).startswith("Pillow was built without XCB support") - with self.assertRaises(IOError) as e: + with pytest.raises(IOError) as e: ImageGrab.grab(xdisplay="") - self.assertTrue( - str(e.exception).startswith("Pillow was built without XCB support") - ) + assert str(e.value).startswith("Pillow was built without XCB support") @unittest.skipUnless(Image.core.HAVE_XCB, "requires XCB") def test_grab_invalid_xdisplay(self): - with self.assertRaises(IOError) as e: + with pytest.raises(IOError) as e: ImageGrab.grab(xdisplay="error.test:0.0") - assert str(e.exception).startswith("X connection failed") + assert str(e.value).startswith("X connection failed") def test_grabclipboard(self): if sys.platform == "darwin": @@ -67,11 +64,9 @@ def test_grabclipboard(self): ) p.communicate() else: - with self.assertRaises(NotImplementedError) as e: + with pytest.raises(NotImplementedError) as e: ImageGrab.grabclipboard() - self.assertEqual( - str(e.exception), "ImageGrab.grabclipboard() is macOS and Windows only" - ) + assert str(e.value) == "ImageGrab.grabclipboard() is macOS and Windows only" return im = ImageGrab.grabclipboard()