LudovicRousseau / pyscard

pyscard smartcard library for python
http://pyscard.sourceforge.net/
GNU Lesser General Public License v2.1
377 stars 108 forks source link

2.0.3: pytest is failing in `test/test_Exceptions.py::TestUtil::test_hresult` unit #129

Closed kloczek closed 1 year ago

kloczek commented 2 years ago

Your system information

Here is pytest output:

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pyscard-2.0.3-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pyscard-2.0.3-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra --import-mode=importlib
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.1, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/pyscard-2.0.3
collected 31 items

test/test_ATR.py ........                                                                                                                                            [ 25%]
test/test_Exceptions.py .....F                                                                                                                                       [ 45%]
test/test_PCSCExceptions.py ......                                                                                                                                   [ 64%]
test/test_SCardGetErrorMessage.py .                                                                                                                                  [ 67%]
test/test_util.py ..........                                                                                                                                         [100%]

================================================================================= FAILURES =================================================================================
__________________________________________________________________________ TestUtil.test_hresult ___________________________________________________________________________

self = <test.test_Exceptions.TestUtil testMethod=test_hresult>

    def test_hresult(self):
        hresult, hcontext = SCardEstablishContext(SCARD_SCOPE_USER)
        if hresult == SCARD_S_SUCCESS:
            hresult, hcard, dwActiveProtocol = SCardConnect(
                hcontext, "INVALID READER NAME", SCARD_SHARE_SHARED, SCARD_PROTOCOL_ANY
            )
            self.assertEqual(hresult, SCARD_E_UNKNOWN_READER)
        else:
>           self.assertEqual(hresult, SCARD_E_NO_SERVICE)
E           AssertionError: 2148532243 != 2148532253

test/test_Exceptions.py:71: AssertionError
========================================================================= short test summary info ==========================================================================
FAILED test/test_Exceptions.py::TestUtil::test_hresult - AssertionError: 2148532243 != 2148532253
======================================================================= 1 failed, 30 passed in 0.49s =======================================================================
LudovicRousseau commented 2 years ago

2148532243 is SCARD_F_COMM_ERROR

Please generate a pcscd log as described at https://pcsclite.apdu.fr/#support

kloczek commented 2 years ago

So I'm guessing that as long as there is no physical card to test this unit may fail? Am I right? 🤔

LudovicRousseau commented 2 years ago

No, you are wrong. Please generate and send me a pcscd log.

LudovicRousseau commented 2 years ago

@kloczek I have no new since 6 days. I need the pcscd log to try to understand what is happening.

kloczek commented 2 years ago

Sorry I was busy. Will try to provide details today evening or tomorrow.

kloczek commented 2 years ago
[tkloczko@devel-g2v SPECS]$ sudo LIBCCID_ifdLogLevel=0x000F pcscd --foreground --debug --apdu --color | tee log.txt
00000000 debuglog.c:299:DebugLogSetLevel() debug level=debug
00000030 debuglog.c:320:DebugLogSetCategory() Debug options: APDU
00000004 [140231278573696] pcscdaemon.c:353:main() Force colored logs
00000070 [140231278573696] pcscdaemon.c:482:main() file /run/pcscd/pcscd.comm already exists.
00000005 [140231278573696] pcscdaemon.c:484:main() Another pcscd (pid: 3916054) seems to be running.

Does it mean that pcscd needs to be started before start pytest?

LudovicRousseau commented 2 years ago
  1. Kill/stop any running pcscd process
  2. Start pcscd to generate the log
  3. run pytest
kloczek commented 2 years ago

Issu is that I'm running all my builds in LXC zones which have no access to many phisical subsystems.

LudovicRousseau commented 2 years ago

"Another pcscd (pid: 3916054) seems to be running." so a pcscd process is already running (or is available) in your LXC.

You can also try to build and run the tests outside your LXC. You do not need to install PySCard. Just run make and make test.

LudovicRousseau commented 2 years ago

Have you tried what I suggested?

LudovicRousseau commented 2 years ago

Any news? Have you found a solution?

LudovicRousseau commented 1 year ago

No news since 4 months. Closing.

kloczek commented 1 year ago

Just tested 1.0.4 and looks like it works now

+ PYTHONPATH=/home/tkloczko/rpmbuild/BUILDROOT/python-pyscard-2.0.4-2.fc35.x86_64/usr/lib64/python3.8/site-packages:/home/tkloczko/rpmbuild/BUILDROOT/python-pyscard-2.0.4-2.fc35.x86_64/usr/lib/python3.8/site-packages
+ /usr/bin/pytest -ra --import-mode=importlib
=========================================================================== test session starts ============================================================================
platform linux -- Python 3.8.13, pytest-7.1.2, pluggy-1.0.0
rootdir: /home/tkloczko/rpmbuild/BUILD/pyscard-2.0.4
collected 34 items

test/test_ATR.py ........                                                                                                                                            [ 23%]
test/test_Exceptions.py ........                                                                                                                                     [ 47%]
test/test_PCSCExceptions.py .......                                                                                                                                  [ 67%]
test/test_SCardGetErrorMessage.py .                                                                                                                                  [ 70%]
test/test_util.py ..........                                                                                                                                         [100%]

============================================================================ 34 passed in 0.14s ============================================================================

Thank you 👍