You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
On another note, I was recently using the pytest-qt module to simulate mouse clicks on a QComboBox in my plugin. I was trying to use their qtbot’s keyClicks to try and change the combo box text.
#36
Closed
kaiguy23 opened this issue
Jun 8, 2023
· 1 comment
On another note, I was recently using the pytest-qt module to simulate mouse clicks on a QComboBox in my plugin. I was trying to use their qtbot’s keyClicks to try and change the combo box text.
For some reason, this seems to work 50% of the time. I have 4 items in my combo box (aspen, bot, bot_train, bot_test) and for some reason the combo box text changes for aspen and bot but not for bot_train and bot_test. I have never seen the combo box fail to switch when I use the plugin myself; this seems to only occur in the test environment.
I saw that you guys have a qgis_bot fixture, but it doesn’t seem to have this keyClicks attribute. Should I be using this module instead, and if so, how should I be using it?
Any advice would be appreciated! This might be a pytest-qt problem, but I figured I should ask here since I am testing a qgis plugin.
Thanks!
For some reason, this seems to work 50% of the time. I have 4 items in my combo box (aspen, bot, bot_train, bot_test) and for some reason the combo box text changes for aspen and bot but not for bot_train and bot_test. I have never seen the combo box fail to switch when I use the plugin myself; this seems to only occur in the test environment.
At least in pytest-qt 3.3.0 choosing items from combo box is not trivial with qtbot if all the starting letters of the items are not unique.
In one project we have this kind of (hacky) helper function to choose item in combo box:
defset_combo_box_value(
qtbot: QtBot, c_box: QComboBox, value: str, strip_values: bool=True, occurence_index: int=0
) ->None:
"""Set combo box value to be the exact string. This handles also the null values"""c_box_values= [
c_box.itemText(i).strip() ifstrip_valueselsec_box.itemText(i)
foriinrange(c_box.count())
]
unique_staring_letters= {
c_box_value[0] ifc_box_valueelse""forc_box_valueinc_box_values
}
ifvalueandlen(unique_staring_letters) ==len(c_box_values):
# By typing the first letter, it changesqtbot.keyClicks(c_box, value[0])
elifvalueinc_box_values:
indexes= [
ifori, c_box_valueinenumerate(c_box_values) ifc_box_value==value
]
c_box.setCurrentIndex(indexes[occurence_index])
else:
# Map layer combo boxes add projection infoclosest_values= [
c_box_valueforc_box_valueinc_box_valuesifc_box_value.startswith(value)
]
ifnotclosest_values:
raiseValueError(
f"Combobox {c_box} does not contain value {value}. It contains values: {closest_values}"
)
c_box.setCurrentText(closest_values[0])
assertc_box.currentText().startswith(value)
I saw that you guys have a qgis_bot fixture, but it doesn’t seem to have this keyClicks attribute. Should I be using this module instead, and if so, how should I be using it?
The naming of the fixture has been inspired by pytest-qt's qtbot, but it has no intention to replace it. In fact I use pytest-qt and qtbot in most of the QGIS plugin projects in addition to pytest-qgis.
For some reason, this seems to work 50% of the time. I have 4 items in my combo box (aspen, bot, bot_train, bot_test) and for some reason the combo box text changes for aspen and bot but not for bot_train and bot_test. I have never seen the combo box fail to switch when I use the plugin myself; this seems to only occur in the test environment.
I saw that you guys have a qgis_bot fixture, but it doesn’t seem to have this keyClicks attribute. Should I be using this module instead, and if so, how should I be using it?
Any advice would be appreciated! This might be a pytest-qt problem, but I figured I should ask here since I am testing a qgis plugin.
Thanks!
Originally posted by @kaiguy23 in #35 (comment)
The text was updated successfully, but these errors were encountered: