Skip to content

Commit

Permalink
Fix tests when run without pcsc
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Jan 15, 2025
1 parent 5a4e34b commit 4e8f758
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
5 changes: 4 additions & 1 deletion tests/device/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ def __init__(self, capmanager, reader_name):
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")

if reader_name:
from fido2.pcsc import _list_readers
try:
from fido2.pcsc import _list_readers
except ImportError:
pytest.exit("pyscard not installed, install package with 'pcsc' extra")

readers = [
r for r in _list_readers() if reader_name.lower() in r.name.lower()
Expand Down
27 changes: 5 additions & 22 deletions tests/test_pcsc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,17 @@
# POSSIBILITY OF SUCH DAMAGE.

from fido2.hid import CTAPHID
from fido2.pcsc import CtapPcscDevice
from unittest import mock
import sys
import pytest


@pytest.fixture(autouse=True, scope="module")
def preconditions():
modules = [
"smartcard",
"smartcard.Exceptions",
"smartcard.System",
"smartcard.CardConnection",
"smartcard.pcsc",
"smartcard.pcsc.PCSCExceptions",
"smartcard.pcsc.PCSCContext",
]

# setup
orig_modules = {}
for m in modules:
orig_modules[m] = sys.modules[m]
sys.modules[m] = mock.Mock()
yield None

# teardown
for m in modules:
sys.modules[m] = orig_modules[m]
global CtapPcscDevice
try:
from fido2.pcsc import CtapPcscDevice
except ImportError:
pytest.skip("pyscard is not installed")


def test_pcsc_call_cbor():
Expand Down

0 comments on commit 4e8f758

Please sign in to comment.