Some trouble running test suite

14 vues
Accéder directement au premier message non lu

Benjamin Buckley

non lue,
31 oct. 2014, 18:20:0531/10/2014
à free...@googlegroups.com
I am in the process of writing some tests for the functions I added to talkeditor.py.

The tests are not really substantial yet. So far, I just have simple placeholder tests to make sure the thing works, e.g.:

    def test_click_talk(self):
        self.assertTrue(True)

... a test which is obviously guaranteed to pass, but which I plan to fill in shortly.

I have run into a bit of a strange problem. In one of my test functions, I have tried to do a little experiment with QTest, just to make sure I'm using it right. My function (which I have put in test_talkeditor.py) looks something like this:

    def test_click_add_talk(self):
        # Click the "Add Talk" button, then click "cancel"
        # This was just a test to see if it could be done -- the "exec_()" method is a bit tricky.
        # This will probably be more useful in test_show_save_prompt()
        QTimer.singleShot(0, self.talk_editor.newTalkWidget.cancelButton, QtCore.SLOT('click()'))
        QtTest.QTest.mouseClick(self.talk_editor.commandButtons.addButton, Qt.Qt.LeftButton)
        self.assertTrue(True)

The idea was to simulate clicking the "Add Talk" button, then click "Cancel". This is a little tricky, because when the "Add Talk" button is clicked, it leads to the method show_new_talk_popup() being called, which leads to newTalkWidget.exec_() being called. The next instruction in the test isn't executed until newTalkWidget receives an "okay" or "cancel", which is tricky, because it means the tests basically stop until someone manually clicks "cancel". Luckily, I found some solutions on StackExchange: http://stackoverflow.com/questions/9518484/test-modal-dialog-with-qt-test. One of the solutions was to use QTimer to automatically click on the Cancel button as quickly as possible (the singleShot method above uses the "click()" method on the cancelButton, after 0 milliseconds).

It's a bit of an odd solution, but it kind of works: when I type in "sudo py.test test_talkeditor.py" all five of my tests pass (the two that were there before I started editing the file, plus test_click_add_talk and two other placeholder tests which do nothing but assert True).

However, when I try to run "sudo ./run_tests.sh" it doesn't seem to work. Everything runs fine until it pytest gets to test_talkeditor.py, when it does this:

[A bunch of other tests]
freeseer/tests/frontend/controller/test_validate.py ......
freeseer/tests/frontend/record/test_record.py .....
freeseer/tests/frontend/reporteditor/test_reporteditor.py ...
freeseer/tests/frontend/talkeditor/test_talkeditor.py ./run_tests.sh: line 3:  3230 Segmentation fault      (core dumped) $COMMAND
@EXIT WITH STATUS: 139
@FAILING...

When the QTimer... and QTest... lines in test_click_add_talk() are commented out with #'s, and I run "sudo ./run_tests.sh", it goes fine. So, apparently there's something about those two lines that pytest doesn't like?

I'm not sure what it means by "segmentation fault" in this context (I mean, if you asked me what a segmentation fault was in a classroom, I might be able to regurgitate some memorized answer about memory access violations, but I don't really get what's going wrong here).

I came across this problem yesterday, and I never made any progress in figuring out what the problem was.
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message