pytest-dev / pytest-qt

pytest plugin for Qt (PyQt5/PyQt6 and PySide2/PySide6) application testing
https://pytest-qt.readthedocs.io
MIT License
410 stars 70 forks source link

adding pytest-qt to requirements.txt result in github action failing on windows for all python versions #579

Closed TonyXTYan closed 2 weeks ago

TonyXTYan commented 2 weeks ago

Hi pytest dev,

When I have pytest-qt in my requirements.tet, and run pytest on github hosted action runners, it will fail for all python versions on windows, whereas the test will pass on macos and ubuntu.

This is the run with pytest-qt included: https://github.com/TonyXTYan/HeLab/actions/runs/11644144376

This is the run with pytest-qt removed: https://github.com/TonyXTYan/HeLab/actions/runs/11644168485

The only difference between those two commits the one line of pytest-qt in requirements.txt.

Attached is the full console (error) message from >pytest -v. error message.txt

nicoddemus commented 2 weeks ago

Hi @TonyXTYan,

I see tests/test_icons_pt.py and tests/test_icons_ut.py, but the log shows:

____________________ ERROR collecting tests/test_icons.py _____________________
ImportError while importing test module 'D:\a\HeLab\HeLab\tests\test_icons.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
C:\hostedtoolcache\windows\Python\3.10.11\x64\lib\importlib\__init__.py:126: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests\test_icons.py:6: in <module>
    from PyQt6.QtGui import QIcon
E   ImportError: DLL load failed while importing QtCore: The specified procedure could not be found.

I assume some step before pytest runs is renaming test_icons_pt.py (pt=pytest) to test_icons.py?

There's an app fixture which caught my eye:

https://github.com/TonyXTYan/HeLab/blob/64c4e13a7d64ef5d13aad3224b523150f1bfe929/tests/test_icons_pt.py#L13-L19

pytest-qt has its own qapp fixture which is responsible for initializing QApplication, perhaps there's some conflict in there. Change your app fixture to:

@pytest.fixture(scope="session", autouse=True)
def init_icons(qapp):
    StatusIcons.initialise_icons()
    return qapp

And see if that helps.

If not, is there anything special that is being done by your test suite to initialize Qt?

TonyXTYan commented 2 weeks ago

Hi @nicoddemus,

I changed the file names and made some squashes since I posted here. Apologies for the confusion.

Changing the @pytest.fixture fixed the problem. Thank you so much for helping.