Is there a way to unit test Gtk / GLib code written in Python?

I am going to write a small medium-sized graphical application with PyGObject (new introspection-based bindings for Gtk). I started with a reasonable nose based test suite that was able to test most of the features of my application by simply importing modules and calling various functions and checking the results.

However, recently I started using some Gtk functions, such as GLib.timeout_add_seconds , which is a pretty simple callback mechanism that just calls the specified callback after the timer expires. The problem that I naturally run into right now is that my code seems to work when I use the application, but testuite is poorly encapsulated, so when one test verifies that it starts with a clean state, it detects that this state was trampled across the callback that was registered by another test. In particular, the test successfully verifies that the files are not downloaded, then downloads some files, and then checks that the files have not been modified since the download, and the test does not work!

It took me a while to figure out what was happening, but essentially one test will change some files (which trigger a timer) and then close them without saving, then another test will open the unmodified files again and find that they have changed because the callback changed files after the timer has risen.

I read about the built-in Python reload() for reloading modules in the hope that I can get it to unload and reload my application to start a new one, but it just doesn't work.

I'm afraid that I may have to start running the application as a subprocess, work with it, and then finish the subprocess and restart it when I need to guarantee a new state. Are there any test frameworks there that would simplify this, especially for pygobject code?

+6
source share

Source: https://habr.com/ru/post/917764/


All Articles