Permalink
Browse files

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'
  • Loading branch information...
1 parent aa7634c commit fb0e0b609827cc960b626da1f0e3e59790f73ad9 @dianaclarke dianaclarke committed with reedobrien Mar 12, 2012
Showing with 13 additions and 4 deletions.
  1. +13 −4 pyramid/tests/test_scripts/test_pserve.py
@@ -1,3 +1,4 @@
+import atexit
import __builtin__
import os
import tempfile
@@ -97,7 +98,6 @@ def test_record_pid_not_verbose(self):
def _remove_pid_unlink_exception(self, inst):
old_unlink = os.unlink
-
def fake_unlink(filename):
raise OSError('Some OSError - unlink')
@@ -109,12 +109,11 @@ def fake_unlink(filename):
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 @@ def _assert_pid_file_not_removed(self, msg):
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:

0 comments on commit fb0e0b6

Please sign in to comment.