summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2016-12-04 16:46:05 -0500
committerNed Batchelder <ned@nedbatchelder.com>2016-12-04 16:46:05 -0500
commit45e9870ba232982e1e0d91ad56f41335c211a977 (patch)
treef29bd1155ae67b99af77609dd1990f1cfcffb81c
parente7e83ee1a65b74b351bc633b9563cdf560eebde1 (diff)
downloadpython-coveragepy-git-45e9870ba232982e1e0d91ad56f41335c211a977.tar.gz
Quick hack to try avoiding stepping on each others' pth files
-rw-r--r--tests/test_process.py36
-rw-r--r--tox.ini1
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):
diff --git a/tox.ini b/tox.ini
index ca662669..6f567494 100644
--- a/tox.ini
+++ b/tox.ini
@@ -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