Skip to content
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

Merged
merged 25 commits into from
Jun 6, 2015
Merged

Capture Qt log messages #40

merged 25 commits into from
Jun 6, 2015

Conversation

nicoddemus
Copy link
Member

WIP:

  • Capture and display Qt messages
  • Disable capture using command line
  • Implement fixture to access captured messages
  • Control formatting using command line
  • Option to output messages directly to stderr instead of capturing them (in discussion: Capturing Qt logging #39)
  • Docs

Fixes #39

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.71%) to 98.29% when pulling 89388e5 on logging into a48b50b on master.

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
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.38%) to 97.62% when pulling 7d8b729 on logging into a48b50b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.34%) to 97.66% when pulling de7f7c5 on logging into a48b50b on master.

Method to be installed using qInstallMsgHandler, stores each message
into the `messages` attribute.
"""
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.52%) to 97.48% when pulling 1ebf18f on logging into a48b50b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.52%) to 97.48% when pulling 465cbf2 on logging into a48b50b on master.

PyQt4 and PySide differ on this aspect, it seems
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.57%) to 98.43% when pulling 6e90e17 on logging into a48b50b on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.57%) to 98.43% when pulling 6e90e17 on logging into a48b50b on master.

qtlog.messages = []


def test_fixture_with_loggin_disabled(testdir):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loggin -> logging 😉

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks. 😄

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.57%) to 98.43% when pulling 344558a on logging into a48b50b on master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.99%) to 98.01% when pulling cccffd4 on logging into a48b50b on master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-1.99%) to 98.01% when pulling cccffd4 on logging into a48b50b on master.

Also, selectively ignore coverage for certain lines that are tested in a separater
process in the tests
@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 6edbea3 on logging into a48b50b on master.

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}')
Copy link
Member

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?

Copy link
Member Author

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. 😄

@nicoddemus nicoddemus mentioned this pull request Jun 2, 2015
nicoddemus added a commit that referenced this pull request Jun 6, 2015
@nicoddemus nicoddemus merged commit ce340a0 into master Jun 6, 2015
@nicoddemus
Copy link
Member Author

Finally merged! 😅

Thanks for all the support @The-Compiler! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Capturing Qt logging
3 participants