From 8582a1ba1ad6b1287f638c9ac21cc4de8eb8dc22 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Thu, 23 Aug 2018 16:59:09 +0200 Subject: [PATCH] Mock application in unit tests --- tests/conftest.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f2c709d8d8..77d215815a 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -3,19 +3,21 @@ # The purpose of this class is to create fixtures or methods that can be shared among all tests. +import unittest.mock import pytest + from UM.Qt.QtApplication import QtApplication #QtApplication import is required, even though it isn't used. from cura.CuraApplication import CuraApplication from cura.MachineActionManager import MachineActionManager + + # Create a CuraApplication object that will be shared among all tests. It needs to be initialized. # Since we need to use it more that once, we create the application the first time and use its instance afterwards. @pytest.fixture() def application() -> CuraApplication: - application = CuraApplication.getInstance() - if application is None: - application = CuraApplication() - return application + app = unittest.mock.MagicMock() + return app # Returns a MachineActionManager instance. @pytest.fixture()