Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 223349c

Browse files
committed
Fixes #25097: Windows test is skipped if there are insufficient privileges, rather than failing.
1 parent f223c53 commit 223349c

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

Lib/test/test_logging.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,10 @@
6565
except ImportError:
6666
threading = None
6767
try:
68-
import win32evtlog
68+
import win32evtlog, win32evtlogutil, pywintypes
6969
except ImportError:
70-
win32evtlog = None
71-
try:
72-
import win32evtlogutil
73-
except ImportError:
74-
win32evtlogutil = None
75-
win32evtlog = None
70+
win32evtlog = win32evtlogutil = pywintypes = None
71+
7672
try:
7773
import zlib
7874
except ImportError:
@@ -4098,13 +4094,19 @@ def test_compute_rollover(self, when=when, exp=exp):
40984094
setattr(TimedRotatingFileHandlerTest, "test_compute_rollover_%s" % when, test_compute_rollover)
40994095

41004096

4101-
@unittest.skipUnless(win32evtlog, 'win32evtlog/win32evtlogutil required for this test.')
4097+
@unittest.skipUnless(win32evtlog, 'win32evtlog/win32evtlogutil/pywintypes required for this test.')
41024098
class NTEventLogHandlerTest(BaseTest):
41034099
def test_basic(self):
41044100
logtype = 'Application'
41054101
elh = win32evtlog.OpenEventLog(None, logtype)
41064102
num_recs = win32evtlog.GetNumberOfEventLogRecords(elh)
4107-
h = logging.handlers.NTEventLogHandler('test_logging')
4103+
4104+
try:
4105+
h = logging.handlers.NTEventLogHandler('test_logging')
4106+
except pywintypes.error as e:
4107+
if e[0] == 5: # access denied
4108+
raise unittest.SkipTest('Insufficient privileges to run test')
4109+
41084110
r = logging.makeLogRecord({'msg': 'Test Log Message'})
41094111
h.handle(r)
41104112
h.close()

0 commit comments

Comments
 (0)