Coder Social home page Coder Social logo

pyqttestexample's People

Contributors

jmcgeheeiv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

pyqttestexample's Issues

Demonstrate event handling and signals in example code

Commenter Rob raised this issue in the comments of deprecated blog article https://johnnado.com/pyqt-qtest-example/.

In their response, Tord gives a solution. This needs to be added to the example code.

Rob

October 22, 2015 @ 3:10 am

Nice article, John, and I have this working for my own app. Thanks! But I’m a bit disappointed because I have events connected to the widgets, but the widgets don’t signal when their values change. In retrospect, this isn’t a surprise, because app.exec_() isn’t called. I thought about putting app.exec_() on a thread, but apparently that’s a big no-no. The best I can do is after I change a value with QTest, I can all the event handler manually. But whether the correct event handler is called should be part of what I’m testing! IMHO, it seems like all we can do is test whether PyQt can change its widget values, not whether our GUIs actually respond to widget changes in the correct manner. Any ideas?

Tord replied

September 23, 2017 @ 11:28 pm

Hi, i have managed to get signalling working for my application, i think in general that signalling should work but i think you have to have everything connected to the same “root object”, i do like this:

When starting the application normally (not in test mode):

my_qapplication = QtWidgets.QApplication(sys.argv)
my_main = mc.matc_main.MyMainClass(my_qapplication)
my_main.main_window_qmainwindow.show()
sys.exit(my_qapplication.exec_())

For the tests:

test_app = QtWidgets.QApplication(sys.argv) # – just before the test class

my_main = mc.matc_main.MyMainClass(test_app) # -at the start of the test function where i want to use it

Also i found out that there’s something called “signal spy" which i haven’t checked out yet but which may be interesting as well.

Demonstrate usage with pytest

Commenter Charlotte Godley raised this issue in the comments of deprecated blog article https://johnnado.com/pyqt-qtest-example/. In their response, Tord added links to the pytest plugin that would be used for this.

This needs to be implemented:

  • Demonstrate running PyQt tests under pytest in the example code
  • Add a brief explanation of running PyQt tests under pytest in README.md

Charlotte Godley

October 16, 2016 @ 4:30 pm

Hey,
Re other people’s comments about unittest and pyqt, I found it much easier to fix these issues using pytest because you can scope your fixtures. Means you have to move to a whole different way of working though (injecting fixtures using parameters rather than class values).

Other thing I’m trying to work on right now is testing actions and menus, which are different because you apparently can’t use mouseClick for actions. You wouldn’t happen to know anything about that would you?

Tord replied

September 26, 2017 @ 11:47 am

Just for reference for those finding this article (thank you John for writing it), the plugin for pytest used for running tests for PyQt is called pytest-qt:

Kind Regards, Tord

Demonstrate testing `getSaveFileName()` dialogs

Dan raised this issue in the comments of deprecated blog article https://johnnado.com/pyqt-qtest-example/.

This may be a duplicate of #4.

Dan

December 13, 2020 @ 11:50 am

Helpful tutorial thanks! Does anybody know a good way to test the getSaveFileName() dialogs? For example, you click File -> Save As – and then a modal dialog appears asking for the location and name of the file you want to save. When completed we should be able to assert a new file has been created somewhere (or at least the dialog generated a path). Is there anyway to complete this using unittest and QTest? Thanks!

Merge johnnado.com blog article into README.md

Currently blog article https://johnnado.com/pyqt-qtest-example/ is separate from the example code here on GitHub.

Demonstrate launching and accepting results from modal dialogs

Tord raised this issue in the comments of deprecated blog article https://johnnado.com/pyqt-qtest-example/.

This needs to be demonstrated in the example code and documented in README.md.

Tord

January 24, 2018 @ 5:01 pm

Hi and thank you for a great article! I wanted to ask: How can we test launching and accepting results from modal dialogs? In our project when we try to do this the execution freezed at “exec_” for the modal dialog. Can signals be used somehow or is there another approach? Kind Regards, Tord

Tord replied

January 24, 2018 @ 6:23 pm

I’ve found out that there are two ways to create modal dialogs, you don’t have to use .exec_(), instead you can use .setModal(True) and .show(). It does require a slightly different approach but it solves the problem described above

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.