summaryrefslogtreecommitdiff
path: root/tests/test_process.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_process.py')
-rw-r--r--tests/test_process.py42
1 files changed, 29 insertions, 13 deletions
diff --git a/tests/test_process.py b/tests/test_process.py
index dda43ba8..2e94c19a 100644
--- a/tests/test_process.py
+++ b/tests/test_process.py
@@ -11,6 +11,8 @@ import re
import sys
import textwrap
+import pytest
+
import coverage
from coverage import env, CoverageData
from coverage.misc import output_encoding
@@ -692,6 +694,7 @@ class ProcessTest(CoverageTest):
self.assertEqual(len(infos), 1)
self.assertEqual(infos[0]['note'], u"These are musical notes: ♫𝅗𝅥♩")
+ @pytest.mark.expensive
def test_fullcoverage(self): # pragma: not covered
if env.PY2: # This doesn't work on Python 2.
self.skipTest("fullcoverage doesn't work on Python 2.")
@@ -1139,25 +1142,38 @@ def possible_pth_dirs():
yield distutils.sysconfig.get_python_lib()
+def find_writable_pth_directory():
+ """Find a place to write a .pth file."""
+ for pth_dir in possible_pth_dirs(): # pragma: part covered
+ try_it = os.path.join(pth_dir, "touch_{0}.it".format(WORKER))
+ with open(try_it, "w") as f:
+ try:
+ f.write("foo")
+ except (IOError, OSError): # pragma: not covered
+ continue
+
+ os.remove(try_it)
+ return pth_dir
+
+ return None
+
+WORKER = os.environ.get('PYTEST_XDIST_WORKER', '')
+PTH_DIR = find_writable_pth_directory()
+
+
class ProcessCoverageMixin(object):
"""Set up a .pth file to coverage-measure all sub-processes."""
def setUp(self):
super(ProcessCoverageMixin, self).setUp()
- # Find a place to put a .pth file.
+
+ # Create the .pth file.
+ self.assert_(PTH_DIR)
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_{0}.pth".format(WORKER))
+ with open(pth_path, "w") as pth:
+ pth.write(pth_contents)
+ self.pth_path = pth_path
self.addCleanup(os.remove, self.pth_path)