diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-04 16:46:05 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2016-12-04 16:46:05 -0500 |
commit | 01b3ccc3857eedbb05c27b45995800e25d46997e (patch) | |
tree | 9529d78fff4f5d0e26a6d0512c0cd8994584fd5b /tests/test_process.py | |
parent | db21d803082f12ae3982ea358be42fa8fa9451c8 (diff) | |
download | python-coveragepy-01b3ccc3857eedbb05c27b45995800e25d46997e.tar.gz |
Quick hack to try avoiding stepping on each others' pth files
Diffstat (limited to 'tests/test_process.py')
-rw-r--r-- | tests/test_process.py | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/tests/test_process.py b/tests/test_process.py index 75d420a..aa536d0 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): |