summaryrefslogtreecommitdiffstats
path: root/src/testlib/qtestcase.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/testlib/qtestcase.cpp')
-rw-r--r--src/testlib/qtestcase.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp
index 6c7e71294ed..784e69d2486 100644
--- a/src/testlib/qtestcase.cpp
+++ b/src/testlib/qtestcase.cpp
@@ -393,6 +393,7 @@ static QString mainSourcePath;
static bool inTestFunction = false;
#if defined(Q_OS_MACOS)
+static std::optional<QTestPrivate::AppNapDisabler> appNapDisabler;
static IOPMAssertionID macPowerSavingDisabled = 0;
#endif
@@ -1881,13 +1882,12 @@ void QTest::qInit(QObject *testObject, int argc, char **argv)
QTestPrivate::disableWindowRestore();
// Disable App Nap which may cause tests to stall
- QTestPrivate::AppNapDisabler appNapDisabler;
+ if (!appNapDisabler)
+ appNapDisabler.emplace();
- if (qApp && (qstrcmp(qApp->metaObject()->className(), "QApplication") == 0)) {
- IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
- kIOPMAssertionLevelOn, CFSTR("QtTest running tests"),
- &macPowerSavingDisabled);
- }
+ IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep,
+ kIOPMAssertionLevelOn, CFSTR("QtTest running tests"),
+ &macPowerSavingDisabled);
#endif
QTestPrivate::parseBlackList();
@@ -2041,6 +2041,7 @@ void QTest::qCleanup()
#if defined(Q_OS_MACOS)
IOPMAssertionRelease(macPowerSavingDisabled);
+ appNapDisabler = std::nullopt;
#endif
}