@@ -407,12 +407,14 @@ 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 )
416418 # Waits until the LDAP server socket is open, or slapd crashed
417419 deadline = time .monotonic () + 10
418420 # no cover to avoid spurious coverage changes, see
@@ -452,15 +454,16 @@ def start(self):
452454 self ._proc .pid , self .ldap_uri , self .ldapi_uri
453455 )
454456
455- def stop (self ):
457+ def stop (self , cleanup = True ):
456458 """
457459 Stops the slapd server, and waits for it to terminate and cleans up
458460 """
459461 if self ._proc is not None :
460462 self ._log .debug ('stopping slapd with pid %d' , self ._proc .pid )
461463 self ._proc .terminate ()
462464 self .wait ()
463- self ._cleanup_rundir ()
465+ if cleanup :
466+ self ._cleanup_rundir ()
464467 atexit .unregister (self .stop )
465468
466469 def restart (self ):
@@ -588,7 +591,7 @@ def __enter__(self):
588591 return self
589592
590593 def __exit__ (self , exc_type , exc_value , traceback ):
591- self .stop ()
594+ self .stop (exc_type is None )
592595
593596
594597class SlapdTestCase (unittest .TestCase ):
@@ -617,4 +620,4 @@ def setUpClass(cls):
617620
618621 @classmethod
619622 def tearDownClass (cls ):
620- cls .server .stop ()
623+ cls .server .stop (False )
0 commit comments