Skip to content

Commit

Permalink
Clean the global logger at the end of the test.
Browse files Browse the repository at this point in the history
  • Loading branch information
adiroiban committed Mar 18, 2021
1 parent fd06ac2 commit 23f6654
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/twisted/test/test_twistd.py
Original file line number Diff line number Diff line change
Expand Up @@ -1542,9 +1542,10 @@ def test_getLogObserverFile(self):
"""
logFiles = _patchTextFileLogObserver(self.patch)
filename = self.mktemp()
logger = app.AppLogger({"logfile": filename})
sut = app.AppLogger({"logfile": filename})

logger._getLogObserver()
observer = sut._getLogObserver()
self.addCleanup(logger.globalLogPublisher.removeObserver, observer)

self.assertEqual(len(logFiles), 1)
self.assertEqual(logFiles[0].path, os.path.abspath(filename))
Expand Down Expand Up @@ -1595,7 +1596,7 @@ def __call__(self, x):

self.assertIn("starting up", textFromEventDict(logs[0]))
warnings = self.flushWarnings([self.test_legacyObservers])
self.assertEqual(len(warnings), 0)
self.assertEqual(len(warnings), 0, warnings)

def test_unmarkedObserversDeprecated(self):
"""
Expand All @@ -1611,7 +1612,7 @@ def test_unmarkedObserversDeprecated(self):
self.assertIn("starting up", textFromEventDict(logs[0]))

warnings = self.flushWarnings([self.test_unmarkedObserversDeprecated])
self.assertEqual(len(warnings), 1)
self.assertEqual(len(warnings), 1, warnings)
self.assertEqual(
warnings[0]["message"],
(
Expand Down Expand Up @@ -1683,8 +1684,10 @@ def test_getLogObserverFile(self):
"""
logFiles = _patchTextFileLogObserver(self.patch)
filename = self.mktemp()
logger = UnixAppLogger({"logfile": filename})
logger._getLogObserver()
sut = UnixAppLogger({"logfile": filename})

observer = sut._getLogObserver()
self.addCleanup(logger.globalLogPublisher.removeObserver, observer)

self.assertEqual(len(logFiles), 1)
self.assertEqual(logFiles[0].path, os.path.abspath(filename))
Expand Down Expand Up @@ -1715,8 +1718,10 @@ def fakeGetSignal(sig):

self.patch(signal, "getsignal", fakeGetSignal)
filename = self.mktemp()
logger = UnixAppLogger({"logfile": filename})
logger._getLogObserver()
sut = UnixAppLogger({"logfile": filename})

observer = sut._getLogObserver()
self.addCleanup(logger.globalLogPublisher.removeObserver, observer)

self.assertEqual(self.signals, [])

Expand Down

0 comments on commit 23f6654

Please sign in to comment.