I have a menu that I created
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None)
...
create_menu_bar()
...
def create_menu_bar(self):
sheet_one = QtWidgets.QAction("sheet_one", self)
sheet_one.triggered.connect(lambda: self.load_df(sheet_name="sheet one"))
# more QActions createad
menu = self.menuBar()
menu.addAction(sheet_one)
# drop down list
sheet_five_menu = menu.addMenu("&sheet five")
sheet_five_menu.addAction(sheet_five_one)
sheet_five_menu.addAction(sheet_five_two)
...
I am trying to use pytest-qt to imitate a user clicking on one of the menu options, or clicking on one of the drop down menu options from sheet_five_menu
After reading the documentation I have been able to understand how to open a window and view it. But I am having trouble understanding how to imitate user mouse clicks on my implementation of the menu. I read this stackoverflow, implemented, but got this error.
E AttributeError: 'NoneType' object has no attribute 'triggered'
test_app.py:11: AttributeError
what my test code currently looks like
def test_menu(qtbot):
window = my_app.MainWindow()
qtbot.add_widget(window)
window.show()
window.findChild(QtWidgets.QAction, 'sheet_one').trigger()
EDIT
reading this qt docs I understand that I should be able to trigger the QAction in this way but I am also getting error
revised code :
window.sheet_one.trigger()
but I am getting this error:
E AttributeError: 'MainWindow' object has no attribute 'sheet_one'
I also tried example:
menu = window.create_menu_bar()
menu.actions()[0]
menu.trigger()
but am getting this error:
E AttributeError: 'NoneType' object has no attribute 'trigger'