From 03dfcebb082caa29823262ed2137c29c06aa4349 Mon Sep 17 00:00:00 2001 From: dianaclarke Date: Mon, 12 Mar 2012 19:36:08 -0400 Subject: monkey patch atexit, since it seems to be gernerating this error in same cases (but all the tests still pass) Ran 2083 tests in 8.913s OK Error in atexit._run_exitfuncs: Traceback (most recent call last): File "/usr/lib/python2.6/atexit.py", line 24, in _run_exitfuncs func(*targs, **kargs) File "/mnt/hgfs/workspace/pyramid/pyramid/scripts/pserve.py", line 400, in _remove_pid_file current_pid = os.getpid() AttributeError: 'NoneType' object has no attribute 'getpid' --- pyramid/tests/test_scripts/test_pserve.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/pyramid/tests/test_scripts/test_pserve.py b/pyramid/tests/test_scripts/test_pserve.py index c1b91e3ae..6417791f3 100644 --- a/pyramid/tests/test_scripts/test_pserve.py +++ b/pyramid/tests/test_scripts/test_pserve.py @@ -1,3 +1,4 @@ +import atexit import __builtin__ import os import tempfile @@ -97,7 +98,6 @@ class TestPServeCommand(unittest.TestCase): def _remove_pid_unlink_exception(self, inst): old_unlink = os.unlink - def fake_unlink(filename): raise OSError('Some OSError - unlink') @@ -109,12 +109,11 @@ class TestPServeCommand(unittest.TestCase): def _remove_pid_unlink_and_write_exceptions(self, inst): old_unlink = os.unlink - old_open = __builtin__.open - def fake_unlink(filename): raise OSError('Some OSError - unlink') run_already = [] + old_open = __builtin__.open def fake_open(*args): if not run_already: run_already.append(True) @@ -139,11 +138,21 @@ class TestPServeCommand(unittest.TestCase): self.assertEqual(self.out_.getvalue(), msg) def _assert_record_pid(self, verbosity, msg): + old_atexit = atexit.register + def fake_atexit(*args): + pass + self.pid_file = tempfile.mktemp() pid = os.getpid() inst = self._makeOne() inst.verbose = verbosity - inst.record_pid(self.pid_file) + + try: + atexit.register = fake_atexit + inst.record_pid(self.pid_file) + finally: + atexit.register = old_atexit + msg = msg % (pid, self.pid_file) if msg else '' self.assertEqual(self.out_.getvalue(), msg) with open(self.pid_file) as f: -- cgit v1.2.3