diff --git a/Applications/SlicerApp/Testing/Python/CMakeLists.txt b/Applications/SlicerApp/Testing/Python/CMakeLists.txt index 4e550763345..f7e25617fd4 100644 --- a/Applications/SlicerApp/Testing/Python/CMakeLists.txt +++ b/Applications/SlicerApp/Testing/Python/CMakeLists.txt @@ -89,6 +89,13 @@ slicer_add_python_test(SCRIPT SlicerTestingExitSuccessTest.py) slicer_add_python_test(SCRIPT SlicerTestingExitFailureTest.py) set_tests_properties(py_SlicerTestingExitFailureTest PROPERTIES WILL_FAIL TRUE) +slicer_add_python_test( + SCRIPT SlicerTestingWithNonExistentScriptTest.py + SLICER_ARGS --no-main-window --disable-modules --exit-after-startup + TESTNAME_PREFIX nomainwindow_ + ) +set_tests_properties(py_nomainwindow_SlicerTestingWithNonExistentScriptTest PROPERTIES WILL_FAIL TRUE) + # # Check if 'slicer.testing.runUnitTest()' works as expected # diff --git a/Base/QTCore/qSlicerCoreApplication.cxx b/Base/QTCore/qSlicerCoreApplication.cxx index 33d0320c374..9cace251e94 100644 --- a/Base/QTCore/qSlicerCoreApplication.cxx +++ b/Base/QTCore/qSlicerCoreApplication.cxx @@ -928,14 +928,15 @@ void qSlicerCoreApplication::handleCommandLineArguments() // Execute python script if(!pythonScript.isEmpty()) { + qApp->processEvents(); if (QFile::exists(pythonScript)) { - qApp->processEvents(); this->corePythonManager()->executeFile(pythonScript); } else { - qWarning() << "Specified python script doesn't exist:" << pythonScript; + this->corePythonManager()->executeString( + QString("raise RuntimeError(\"Specified python script doesn't exist: %1\")").arg(pythonScript)); } } QString pythonCode = options->pythonCode();