diff --git a/src/Gui/MainWindow.cpp b/src/Gui/MainWindow.cpp index 53862b8656..6bbc6098fb 100644 --- a/src/Gui/MainWindow.cpp +++ b/src/Gui/MainWindow.cpp @@ -1291,15 +1291,26 @@ void MainWindow::delayedStartup() { // automatically run unit tests in Gui if (App::Application::Config()["RunMode"] == "Internal") { - try { - Base::Interpreter().runString(Base::ScriptFactory().ProduceScript("FreeCADTest")); - } - catch (const Base::SystemExitException&) { - throw; - } - catch (const Base::Exception& e) { - e.ReportException(); - } + QTimer::singleShot(1000, this, []{ + try { + Base::Interpreter().runString( + "import sys\n" + "import FreeCAD\n" + "import QtUnitGui\n\n" + "testCase = FreeCAD.ConfigGet(\"TestCase\")\n" + "QtUnitGui.addTest(testCase)\n" + "QtUnitGui.setTest(testCase)\n" + "result = QtUnitGui.runTest()\n" + "sys.stdout.flush()\n" + "sys.exit(0 if result else 1)"); + } + catch (const Base::SystemExitException&) { + throw; + } + catch (const Base::Exception& e) { + e.ReportException(); + } + }); return; } diff --git a/src/Mod/Test/Gui/AppTestGui.cpp b/src/Mod/Test/Gui/AppTestGui.cpp index 37a24992ec..1c445b99e3 100644 --- a/src/Mod/Test/Gui/AppTestGui.cpp +++ b/src/Mod/Test/Gui/AppTestGui.cpp @@ -121,6 +121,7 @@ public: add_varargs_method("UnitTest",&Module::new_UnitTest,"UnitTest"); add_varargs_method("setTest",&Module::setTest,"setTest"); add_varargs_method("addTest",&Module::addTest,"addTest"); + add_varargs_method("runTest",&Module::runTest,"runTest"); add_varargs_method("testILoggerBlocker",&Module::testILoggerBlocker,"testILoggerBlocker"); initialize("This module is the QtUnitGui module"); // register with Python } @@ -160,6 +161,15 @@ private: dlg->raise(); return Py::None(); } + Py::Object runTest(const Py::Tuple& args) + { + if (!PyArg_ParseTuple(args.ptr(), "")) + throw Py::Exception(); + + TestGui::UnitTestDialog* dlg = TestGui::UnitTestDialog::instance(); + bool success = dlg->runCurrentTest(); + return Py::Boolean(success); + } Py::Object testILoggerBlocker(const Py::Tuple& args) { (void) args; ILoggerBlockerTest iltest; diff --git a/src/Mod/Test/Gui/UnitTestImp.cpp b/src/Mod/Test/Gui/UnitTestImp.cpp index e2e8919509..ddbdb6012e 100644 --- a/src/Mod/Test/Gui/UnitTestImp.cpp +++ b/src/Mod/Test/Gui/UnitTestImp.cpp @@ -274,6 +274,19 @@ QString UnitTestDialog::getUnitTest() const return ui->comboTests->currentText(); } +/** + * Runs the currently selected test and closes the dialog afterwards. + * It returns true if all tests have passed and false otherwise. + */ +bool UnitTestDialog::runCurrentTest() +{ + clearErrorList(); + on_startButton_clicked(); + int count = ui->treeViewFailure->topLevelItemCount(); + reject(); + return (count == 0); +} + /** * Sets the text in the status bar. */ diff --git a/src/Mod/Test/Gui/UnitTestImp.h b/src/Mod/Test/Gui/UnitTestImp.h index c8e460921d..54a60e54ef 100644 --- a/src/Mod/Test/Gui/UnitTestImp.h +++ b/src/Mod/Test/Gui/UnitTestImp.h @@ -44,6 +44,7 @@ public: void setUnitTest(const QString& unit); void clearUnitTests(); QString getUnitTest() const; + bool runCurrentTest(); void setStatusText(const QString& text); void setProgressFraction(float fraction, const QString& = QString()); void clearErrorList();