pyscard icon indicating copy to clipboard operation
pyscard copied to clipboard

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

Open kloczek opened this issue 2 years ago • 11 comments

Your system information

  • Operating system used: Linux x86/64
  • pyscard version: pcsc-lite 1.9.5
  • Python version: 3.8.13

Please describe your issue in as much detail as possible:

I'm trying to package your module as an rpm package. So I'm using the typical build, install and test cycle used on building packages from non-root account.

  • "setup.py build"
  • "setup.py install --root </install/prefix>"
  • "pytest with PYTHONPATH pointing to sitearch and sitelib inside </install/prefix>

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 =======================================================================

kloczek avatar Apr 09 '22 08:04 kloczek

2148532243 is SCARD_F_COMM_ERROR

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

LudovicRousseau avatar Apr 09 '22 13:04 LudovicRousseau

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

kloczek avatar Apr 09 '22 14:04 kloczek

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

LudovicRousseau avatar Apr 09 '22 14:04 LudovicRousseau

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

LudovicRousseau avatar Apr 15 '22 13:04 LudovicRousseau

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

kloczek avatar Apr 15 '22 14:04 kloczek

[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?

kloczek avatar Apr 20 '22 17:04 kloczek

  1. Kill/stop any running pcscd process
  2. Start pcscd to generate the log
  3. run pytest

LudovicRousseau avatar Apr 20 '22 20:04 LudovicRousseau

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

kloczek avatar Apr 20 '22 20:04 kloczek

"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 avatar Apr 20 '22 20:04 LudovicRousseau

Have you tried what I suggested?

LudovicRousseau avatar May 07 '22 15:05 LudovicRousseau

Any news? Have you found a solution?

LudovicRousseau avatar Jun 15 '22 12:06 LudovicRousseau

No news since 4 months. Closing.

LudovicRousseau avatar Aug 26 '22 14:08 LudovicRousseau

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 👍

kloczek avatar Aug 28 '22 18:08 kloczek