test: 100% coverage on core modules with headless CI support
Some checks failed
SonarQube Code Quality Scan / SonarQube Scan (push) Failing after 1m20s
Some checks failed
SonarQube Code Quality Scan / SonarQube Scan (push) Failing after 1m20s
- Fix dead exception handler in discord_rpc.py (unreachable DiscordNotFound) - Replace QMediaPlayer=None stub with proper _StubQMediaPlayer in player.py - Make AudioVisualizer color stops Qt-free (raw tuples instead of QColor) - Add conftest QApplication creation check for headless CI detection - Add test_gui_widgets.py _qt_available() guard for headless environments - Add test_main.py (30 tests) for main.py entry point and env vars - Add test_import_fallbacks.py (14 tests) for Qt import fallback paths - Extend test_gui_helpers.py with _css, _get_thumbnail_nam, _cached_thumb_path tests - Extend test_discord_rpc.py with direct _connect() test for DiscordNotFound - Extend test_player_helpers.py with SearchWorker test-mode tests - Ensure import fallback tests clean up sys.modules to avoid cross-test pollution 100% coverage achieved on: config.py, discord_rpc.py, main.py, music_db.py
This commit is contained in:
@@ -14,12 +14,26 @@ from unittest import mock
|
||||
import pytest
|
||||
|
||||
# The conftest stubs PySide6.QtWidgets as a MagicMock when Qt is
|
||||
# unavailable (headless CI). ``importorskip`` succeeds on the mock
|
||||
# module, so we check the actual class type instead.
|
||||
# unavailable (headless CI). We check whether we have a real Qt runtime
|
||||
# by verifying QApplication is not a MagicMock and that it can be created.
|
||||
from PySide6.QtWidgets import QApplication, QWidget
|
||||
|
||||
if isinstance(QApplication, mock.MagicMock):
|
||||
pytest.skip("Real Qt runtime not available (stubs active)",
|
||||
def _qt_available() -> bool:
|
||||
"""Return True if a real QApplication can be created (display available)."""
|
||||
if isinstance(QApplication, mock.MagicMock):
|
||||
return False
|
||||
inst = QApplication.instance()
|
||||
if inst is not None:
|
||||
return True
|
||||
try:
|
||||
app = QApplication([])
|
||||
app.quit()
|
||||
return True
|
||||
except (RuntimeError, OSError):
|
||||
return False
|
||||
|
||||
if not _qt_available():
|
||||
pytest.skip("Real Qt runtime not available (stubs active / headless)",
|
||||
allow_module_level=True)
|
||||
|
||||
from PySide6.QtCore import QTimer
|
||||
|
||||
Reference in New Issue
Block a user