Skip to content

Commit b75b160

Browse files
committed
Refactor PIL availability check and update test skip condition
1 parent 7fb34d6 commit b75b160

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

qrcode/tests/test_module.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
import subprocess
22
import sys
33
import tempfile
4+
from importlib.util import find_spec
45
from pathlib import Path
56

67
import pytest
78

8-
try:
9-
from PIL import Image, ImageDraw # noqa: F401
109

11-
PIL_NOT_INSTALLED = False
12-
except ImportError:
13-
PIL_NOT_INSTALLED = True
10+
PIL_NOT_AVAILABLE = find_spec("PIL") is None
1411

1512

1613
def test_module_help():
@@ -31,7 +28,7 @@ def test_module_help():
3128
assert "--factory" in result.stdout
3229

3330

34-
@pytest.mark.skipif(PIL_NOT_INSTALLED, reason="PIL is not installed")
31+
@pytest.mark.skipif(PIL_NOT_AVAILABLE, reason="PIL is not installed")
3532
def test_module_generate_qrcode():
3633
"""Test that the module can generate a QR code image."""
3734
with tempfile.TemporaryDirectory() as temp_dir:

0 commit comments

Comments
 (0)