-
-
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
Log capturing breaks existing logging tests #54
Comments
I think the solution is to simply disable the new feature, since they both seem to conflict: [pytest]
addopts= --no-qt-log I just tested this change in Your suggestion about giving a warning if Thanks for checking out the release so quickly! 😄 |
I looked at the test again now - what it actually tests is the filtering of irrelevant Qt messages inside qutebrowser. qutebrowser redirects Qt warnings to a logger, and then has a custom LogFilter to filter harmless messages (others get displayed). What that test does actually, is testing that filter. So I think there are two possible solutions:
Of course I'd like to avoid using |
Hmm I like the context manager idea... I quickly tried this but the test still fails: def test_unfiltered(self, caplog):
"""Test a message which is not filtered."""
from PyQt5.QtCore import qInstallMessageHandler
try:
old = qInstallMessageHandler(None)
with log.hide_qt_warning("World", logger='qt-tests'):
with caplog.atLevel(logging.WARNING, logger='qt-tests'):
qWarning("Hello World")
finally:
qInstallMessageHandler(old)
assert len(caplog.records()) == 1
record = caplog.records()[0]
assert record.levelname == 'WARNING'
assert record.message == "Hello World" You have something else in mind? |
I fixed the tests by logging directly to the logger which should get filtered instead of Though I still think the context manager thing would be useful - however, at least for my use case, it'd have to restore the original handler (i.e. |
Yeah, I like the context manager idea. Feel free to comment on #56. 😄 |
#40 breaks an existing test in qutebrowser which uses a custom message handler which uses logging and pytest-capturelog.
I'm not sure whether this is an issue, or the kind of breakage which is okay when updating a minor version. If you think it should be fixed, probably the message handler should be restored/left untouched when
qInstallMessageHandler
returns something else thanNone
(and a pytest warning shown?).Another possibility would perhaps be to call the old message handler from the pytest-qt one, so both work?
The text was updated successfully, but these errors were encountered: