16
16
17
17
import pytest
18
18
import os
19
+ from PyQt5 .QtWidgets import QMessageBox
19
20
from PyQt5 import QtCore
20
21
from views .main_window import MainWindow
21
22
@@ -33,6 +34,21 @@ def main_window(qtbot):
33
34
yield main_window
34
35
35
36
37
+ @pytest .fixture
38
+ def mock_qmessagebox (qtbot ):
39
+ """This fixture sinks the QMessageBox to prevent the pop up"""
40
+
41
+ def mock_messagebox (* args , ** kwargs ):
42
+ msgbox = QMessageBox ()
43
+ msgbox .setText ("Mock Message Box" )
44
+ msgbox .setStandardButtons (QMessageBox .Ok )
45
+ return msgbox
46
+
47
+ QMessageBox .warning = mock_messagebox
48
+ QMessageBox .information = mock_messagebox
49
+ QMessageBox .critical = mock_messagebox
50
+
51
+
36
52
def test_main_window (main_window ):
37
53
assert isinstance (main_window , MainWindow )
38
54
@@ -97,8 +113,6 @@ def test_verify_digits(main_window):
97
113
assert main_window .verify_digits () is False
98
114
99
115
100
- # I had trouble closing the error box. Since it's small, I've ommited it.
101
-
102
116
def test_monthly_payment_edit (main_window , qtbot ):
103
117
main_window .ui .monthlyPaymentEdit .clear ()
104
118
qtbot .keyClicks (main_window .ui .monthlyPaymentEdit , "12345" )
@@ -152,7 +166,7 @@ def test_PMI_edit(main_window, qtbot):
152
166
assert main_window .ui .PMIEdit .text () == "0.34"
153
167
154
168
155
- def test_calculate_house (main_window , qtbot ):
169
+ def test_calculate_house (main_window , mock_qmessagebox , qtbot ):
156
170
"""Tests known values and validates the result"""
157
171
# enter values in gui
158
172
main_window .ui .monthlyPaymentEdit .clear ()
@@ -171,7 +185,7 @@ def test_calculate_house(main_window, qtbot):
171
185
assert main_window .ui .downPaymentHeaderLabel .text () == "Down Payment: 0%"
172
186
173
187
174
- def test_calculate_house_2 (main_window , qtbot ):
188
+ def test_calculate_house_2 (main_window , mock_qmessagebox , qtbot ):
175
189
"""Tests known values and validates the result"""
176
190
# enter values in gui
177
191
main_window .ui .monthlyPaymentEdit .clear ()
@@ -194,7 +208,7 @@ def test_calculate_house_2(main_window, qtbot):
194
208
assert main_window .ui .downPaymentHeaderLabel .text () == "Down Payment: 18%"
195
209
196
210
197
- def test_calculate_house_3 (main_window , qtbot ):
211
+ def test_calculate_house_3 (main_window , mock_qmessagebox , qtbot ):
198
212
"""Third calculation test adding PMI and insurance"""
199
213
# enter values in gui
200
214
main_window .ui .monthlyPaymentEdit .clear ()
0 commit comments