-
-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture Qt log messages #40
Conversation
Now using hookwrapper decorator, supported only by >= 2.7
Use utf-8 as a guess here, but make sure encoding errors don't prevent a message from being displayed
Method to be installed using qInstallMsgHandler, stores each message | ||
into the `messages` attribute. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isinstance(msg, bytes)
is usually the more idomatic way to do this 😉
Though will this ever be a bytes
object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, changed it.
PyQt4 in Python 3 returns bytes
... thought odd too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Qt4's qInstallMsgHandler
actually takes a QtMsgHandler
which takes a const char *
(Qt5 takes a QString
) - so it actually makes sense to map that to a bytes
object in Python3.
PyQt4 and PySide differ on this aspect, it seems
1 similar comment
qtlog.messages = [] | ||
|
||
|
||
def test_fixture_with_loggin_disabled(testdir): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
loggin -> logging 😉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks. 😄
Reuse same ideas and terminology from `logging` when possible
1 similar comment
Also, selectively ignore coverage for certain lines that are tested in a separater process in the tests
parser.addoption('--no-qt-log', dest='qt_log', action='store_false', | ||
default=True) | ||
parser.addoption('--qt-log-format', dest='qt_log_format', | ||
default='{rec.type_name}: {rec.message}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe those should also be .ini options? i.e. why is qt_no_exception_capture
a config option, but --no-qt-log
a commandline flag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was planning on add them as ini options too, but realized it is not really needed as the users can use addopts
instead:
[pytest]
addopts = --qt-log-format="{rec.type_name}"
(I have to remember to add this to the documentation)
qt_no_exception_capture
is a config option because it is "part" of the configuration of the test suite, as it is not something the user should have to pass in the command line for the test suite to work. python_files
follows the same idea, if a test suite uses ut_
prefix for test files, it makes sense that this is configured "permanently" in the ini file, instead of having to be passed every time on the command line.
Hope my somewhat contrived explanation makes sense. 😄
Conflicts: .travis.yml pytestqt/plugin.py
Finally merged! 😅 Thanks for all the support @The-Compiler! 😄 |
WIP:
Fixes #39