Skip to content

Commit 4e8f758

Browse files
committed
Fix tests when run without pcsc
1 parent 5a4e34b commit 4e8f758

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

tests/device/conftest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ def __init__(self, capmanager, reader_name):
4646
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
4747

4848
if reader_name:
49-
from fido2.pcsc import _list_readers
49+
try:
50+
from fido2.pcsc import _list_readers
51+
except ImportError:
52+
pytest.exit("pyscard not installed, install package with 'pcsc' extra")
5053

5154
readers = [
5255
r for r in _list_readers() if reader_name.lower() in r.name.lower()

tests/test_pcsc.py

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,34 +26,17 @@
2626
# POSSIBILITY OF SUCH DAMAGE.
2727

2828
from fido2.hid import CTAPHID
29-
from fido2.pcsc import CtapPcscDevice
3029
from unittest import mock
31-
import sys
3230
import pytest
3331

3432

3533
@pytest.fixture(autouse=True, scope="module")
3634
def preconditions():
37-
modules = [
38-
"smartcard",
39-
"smartcard.Exceptions",
40-
"smartcard.System",
41-
"smartcard.CardConnection",
42-
"smartcard.pcsc",
43-
"smartcard.pcsc.PCSCExceptions",
44-
"smartcard.pcsc.PCSCContext",
45-
]
46-
47-
# setup
48-
orig_modules = {}
49-
for m in modules:
50-
orig_modules[m] = sys.modules[m]
51-
sys.modules[m] = mock.Mock()
52-
yield None
53-
54-
# teardown
55-
for m in modules:
56-
sys.modules[m] = orig_modules[m]
35+
global CtapPcscDevice
36+
try:
37+
from fido2.pcsc import CtapPcscDevice
38+
except ImportError:
39+
pytest.skip("pyscard is not installed")
5740

5841

5942
def test_pcsc_call_cbor():

0 commit comments

Comments
 (0)