-
-
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
fix(mousepress): replace QTest
mouse actions
#429
fix(mousepress): replace QTest
mouse actions
#429
Conversation
`QTest` mouse actions `mouseClick` and `mousePress` do not release the mouse, causing `qtbot` to fail tests. Replace with `QtGui` mouse events. Fixes Issue pytest-dev#428
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 @adam-grant-hendry!
Please take a look at my comments. In addition:
- We should update the documentation to clarify that the new/changed methods are custom implementations (and no longer just forwarding to the QTest API), also pointing out to the relevant discussions if appropriate.
- We need tests for the custom methods: we might not have tests for all of them before because they just forwarded the calls to QTest (which we assumed "worked"), but now we must sure they are tested and covered, to ensure we don't regress.
- Add a new CHANGELOG entry detailing the new methods and the rationale for not using the
QTest
API anymore.
Also I would like to get @The-Compiler's take on this.
def mouseClick(self, widget, button, pos=None, modifiers=None): | ||
if pos is None: | ||
pos = widget.rect().center() | ||
self.mouseMove(widget, pos) |
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.
This doesn't seem right: if I issue a mouseClick
, I don't expect a mouseMove
to be issued.
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.
That's fair: mousePress
and mouseRelease
each take pos
as an argument, so they should click the right spot without moving the cursor.
self.mouseClick(widget, button, pos, modifiers) | ||
self.mouseClick(widget, button, pos, modifiers) | ||
|
||
def mouseDrag(self, widget, button, pos1, pos2, modifiers=None): |
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.
This is new so we should have a docstring and a test.
if isinstance(widget, qt_api.QtWidgets.QGraphicsView): | ||
widget = widget.viewport() |
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.
This if
is specific to pyqtgraph
and should be removed.
if isinstance(widget, qt_api.QtWidgets.QGraphicsView): | |
widget = widget.viewport() |
if isinstance(widget, qt_api.QtWidgets.QGraphicsView): | ||
widget = widget.viewport() |
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.
Same here.
if isinstance(widget, qt_api.QtWidgets.QGraphicsView): | |
widget = widget.viewport() |
@@ -165,17 +164,19 @@ def extract(mouse_event): | |||
|
|||
event_recorder.registerEvent(qt_api.QtGui.QMouseEvent, extract) | |||
|
|||
qtbot.mousePress(event_recorder, qt_api.QtCore.Qt.MouseButton.LeftButton) | |||
qtbot.mousePress( | |||
widget=event_recorder, button=qt_api.QtCore.Qt.MouseButton.LeftButton |
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.
Just to make sure: these changes to the tests are not required, are they?
if isinstance(widget, qt_api.QtWidgets.QGraphicsView): | ||
widget = widget.viewport() |
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.
Same.
if isinstance(widget, qt_api.QtWidgets.QGraphicsView): | |
widget = widget.viewport() |
I'm -1 on this in its entirety. I don't think it's our job to reimplement the QTest methods where we can avoid it, and there is a big chance we're introducing subtle issues and incompatibilities here with very questionable benefit. I don't quite follow on #428 (comment) either. Yes, they are in Above, you also say " Finally, you say:
...again, where are you getting that from? Sorry, but I'm really confused at this point at what the goal of those changes are. As-is, I believe they will introduce more issues than they would fix. |
Thanks @The-Compiler, I did the overall code review but I wasn't certain about the changes too. |
Currently, you cannot avoid it because their are
The
The
The API documentation itself only lists Consequently,
Your documentation does not state what features are known not to work in
That should read
The However, at a minimum, you should add to your documentation those features that will not work (are known not to work) due to
Developers will appreciate you for this and it will spare you bug reports that are to do with |
It would be nice to add an example to the documentation of overriding certain For instance,
|
I'd be fine with adding a workaround for the former - though only on Qt 5, and with a test. What I'm not fine with is reimplementing all of them without having more context why. As for the latter, do your changes fix that as well presently? I'd also be fine with adding a list of such bugs to the troubleshooting page or something - though we can't possibly forsee all issues someone could run into.
Yes, the emphasis being on macros. That is, things from this list like
...you mean
That seems like a documentation bug for PySide2/PySide6 indeed. They exist, have for a long time, and they are in the PyQt API docs too.
I don't think subclassing |
That's entirely fair.
On further investigation, unfortunately no: I found these do not actually solve the problem at hand. From my understanding,
Hence, the menus have to be closed manually (using an Escape key press or clicking outside from QTest will not work). To implement such things, one would have to do what Windows: all which seems very out of scope for this project, as you rightly mentioned. Considering the above, I think this PR should be closed and instead a new PR opened to add a little bit to the documentation.
Ya, we can ignore that.
No, I wouldn't want you to do that. I don't think that's reasonable. I only meant to suggest track things as users find them on a troubleshooting page. For now, I will create a new PR for documentation that simply adds some troubleshooting tips for the bugs I mentioned. |
QTest
mouse actionsmouseClick
andmousePress
do not releasethe mouse, causing
qtbot
to fail tests. Replace withQtGui
mouseevents.
Fixes Issue #428