Skip to content

Commit 1a4d727

Browse files
committed
Store logs and keep failed run data on failure
1 parent 29c3a53 commit 1a4d727

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

Lib/slapdtest/_slapdtest.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,17 @@ def _start_slapd(self):
407407
'-F', self._slapd_conf,
408408
'-h', ' '.join(urls),
409409
]
410+
stderr = None
410411
if self._log.isEnabledFor(logging.DEBUG):
411412
slapd_args.extend(['-d', '-1'])
413+
stderr = os.open(os.path.join(self.testrundir, 'slapd.log'), os.O_WRONLY|os.O_CREAT)
412414
else:
413415
slapd_args.extend(['-d', '0'])
414416
self._log.info('starting slapd: %r', ' '.join(slapd_args))
415-
self._proc = subprocess.Popen(slapd_args)
417+
self._proc = subprocess.Popen(slapd_args, stderr=stderr)
418+
if stderr is not None:
419+
os.close(stderr)
420+
stderr = None
416421
# Waits until the LDAP server socket is open, or slapd crashed
417422
deadline = time.monotonic() + 10
418423
# no cover to avoid spurious coverage changes, see
@@ -452,15 +457,16 @@ def start(self):
452457
self._proc.pid, self.ldap_uri, self.ldapi_uri
453458
)
454459

455-
def stop(self):
460+
def stop(self, cleanup=True):
456461
"""
457462
Stops the slapd server, and waits for it to terminate and cleans up
458463
"""
459464
if self._proc is not None:
460465
self._log.debug('stopping slapd with pid %d', self._proc.pid)
461466
self._proc.terminate()
462467
self.wait()
463-
self._cleanup_rundir()
468+
if cleanup:
469+
self._cleanup_rundir()
464470
atexit.unregister(self.stop)
465471

466472
def restart(self):
@@ -588,7 +594,7 @@ def __enter__(self):
588594
return self
589595

590596
def __exit__(self, exc_type, exc_value, traceback):
591-
self.stop()
597+
self.stop(exc_type is None)
592598

593599

594600
class SlapdTestCase(unittest.TestCase):
@@ -617,4 +623,4 @@ def setUpClass(cls):
617623

618624
@classmethod
619625
def tearDownClass(cls):
620-
cls.server.stop()
626+
cls.server.stop(False)

0 commit comments

Comments
 (0)