diff options
-rw-r--r-- | tests/test_process.py | 36 | ||||
-rw-r--r-- | tox.ini | 1 |
2 files changed, 25 insertions, 12 deletions
diff --git a/tests/test_process.py b/tests/test_process.py index 75d420a0..aa536d08 100644 --- a/tests/test_process.py +++ b/tests/test_process.py @@ -1079,27 +1079,39 @@ def possible_pth_dirs(): yield distutils.sysconfig.get_python_lib() +# Find the writable pth directory +for pth_dir in possible_pth_dirs(): # pragma: part covered + try_it = os.path.join(pth_dir, "touch.it") + with open(try_it, "w") as f: + try: + f.write("foo") + PTH_DIR = pth_dir + break + except (IOError, OSError): # pragma: not covered + pass +else: # pragma: not covered + PTH_DIR = None + +import filelock +if PTH_DIR: + pth_lock = filelock.FileLock(os.path.join(PTH_DIR, "pth.lock")) + + class ProcessCoverageMixin(object): """Set up a .pth file to coverage-measure all sub-processes.""" def setUp(self): super(ProcessCoverageMixin, self).setUp() + pth_lock.acquire() # Find a place to put a .pth file. pth_contents = "import coverage; coverage.process_startup()\n" - for pth_dir in possible_pth_dirs(): # pragma: part covered - worker = os.environ.get('PYTEST_XDIST_WORKER', '') - pth_path = os.path.join(pth_dir, "subcover_{0}.pth".format(worker)) - with open(pth_path, "w") as pth: - try: - pth.write(pth_contents) - self.pth_path = pth_path - break - except (IOError, OSError): # pragma: not covered - pass - else: # pragma: not covered - raise Exception("Couldn't find a place for the .pth file") + pth_path = os.path.join(pth_dir, "subcover.pth") + with open(pth_path, "w") as pth: + pth.write(pth_contents) + self.pth_path = pth_path self.addCleanup(os.remove, self.pth_path) + self.addCleanup(pth_lock.release) class ProcessStartupTest(ProcessCoverageMixin, CoverageTest): @@ -18,6 +18,7 @@ deps = PyContracts==1.7.12 unittest-mixins==1.1.1 #-egit+/Users/ned/unittest_mixins#egg=unittest-mixins==0.0 + filelock py26: unittest2==1.1.0 py{27,33,34,35,36}: gevent==1.1.2 py{26,27,33,34,35,36}: eventlet==0.19.0 |