From 3cc46b7bf100a424c0ea81e2f8b465aaff2a111d Mon Sep 17 00:00:00 2001 From: Kimoon Han Date: Tue, 18 Jun 2024 14:08:02 +0900 Subject: [PATCH] test: add coverage for QThread --- pyproject.toml | 2 +- src/erlab/interactive/imagetool/manager.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 8ccc2994..16e375bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -240,7 +240,7 @@ exclude_also = [ "if __name__ == __main__:", "except varname.VarnameRetrievingError:", "if TYPE_CHECKING:", - "QtCore.QThread", + "_coverage_resolve_trace", ] [tool.mypy] diff --git a/src/erlab/interactive/imagetool/manager.py b/src/erlab/interactive/imagetool/manager.py index be9fcb05..124e605c 100644 --- a/src/erlab/interactive/imagetool/manager.py +++ b/src/erlab/interactive/imagetool/manager.py @@ -2,6 +2,7 @@ from __future__ import annotations +import functools import os import pickle import socket @@ -42,6 +43,17 @@ class ItoolManagerParseError(Exception): """Raised when the data received from the client cannot be parsed.""" +def _coverage_resolve_trace(fn): + # https://github.com/nedbat/coveragepy/issues/686#issuecomment-634932753 + @functools.wraps(fn) + def wrapped(*args, **kwargs): + if threading._trace_hook: + sys.settrace(threading._trace_hook) + fn(*args, **kwargs) + + return wrapped + + class _ManagerServer(QtCore.QThread): sigReceived = QtCore.Signal(list, dict) @@ -49,6 +61,7 @@ def __init__(self): super().__init__() self.stopped = threading.Event() + @_coverage_resolve_trace def run(self): self.stopped.clear() soc = socket.socket()