Use pytest-mock to install QApplication.clipboard mock
This commit is contained in:
parent
2d19708a41
commit
f55242ad93
@ -48,17 +48,17 @@ class TestCommandLineEdit:
|
|||||||
|
|
||||||
objreg.delete('command-history')
|
objreg.delete('command-history')
|
||||||
|
|
||||||
@pytest.yield_fixture
|
@pytest.fixture
|
||||||
def mock_clipboard(self):
|
def mock_clipboard(self, mocker):
|
||||||
"""
|
"""
|
||||||
Fixture installs a MagicMock into QApplication.clipboard() and
|
Fixture installs a MagicMock into QApplication.clipboard() and
|
||||||
returns it.
|
returns it.
|
||||||
"""
|
"""
|
||||||
with mock.patch.object(QApplication, 'clipboard'):
|
mocker.patch.object(QApplication, 'clipboard')
|
||||||
clipboard = mock.MagicMock()
|
clipboard = mock.MagicMock()
|
||||||
clipboard.supportsSelection.return_value = True
|
clipboard.supportsSelection.return_value = True
|
||||||
QApplication.clipboard.return_value = clipboard
|
QApplication.clipboard.return_value = clipboard
|
||||||
yield clipboard
|
return clipboard
|
||||||
|
|
||||||
def test_position(self, qtbot, cmd_edit):
|
def test_position(self, qtbot, cmd_edit):
|
||||||
"""Test cursor position based on the prompt."""
|
"""Test cursor position based on the prompt."""
|
||||||
|
Loading…
Reference in New Issue
Block a user