summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--coverage/control.py26
-rw-r--r--coverage/data.py18
-rw-r--r--coverage/debug.py3
-rw-r--r--tests/coveragetest.py2
-rw-r--r--tests/test_data.py4
-rw-r--r--tests/test_farm.py2
6 files changed, 26 insertions, 29 deletions
diff --git a/coverage/control.py b/coverage/control.py
index 84d5d030..ca3660ac 100644
--- a/coverage/control.py
+++ b/coverage/control.py
@@ -4,8 +4,6 @@ import atexit
import inspect
import os
import platform
-import random
-import socket
import sys
import traceback
@@ -283,7 +281,7 @@ class Coverage(object):
# environments (virtualenv, for example), these modules may be
# spread across a few locations. Look at all the candidate modules
# we've imported, and take all the different ones.
- for m in (atexit, os, platform, random, socket, _structseq):
+ for m in (atexit, inspect, os, platform, _structseq, traceback):
if m is not None and hasattr(m, "__file__"):
self.pylib_dirs.add(self._canonical_dir(m))
if _structseq and not hasattr(_structseq, '__file__'):
@@ -708,24 +706,8 @@ class Coverage(object):
def save(self):
"""Save the collected coverage data to the data file."""
self._init()
- data_suffix = self.data_suffix
- if data_suffix is True:
- # If data_suffix was a simple true value, then make a suffix with
- # plenty of distinguishing information. We do this here in
- # `save()` at the last minute so that the pid will be correct even
- # if the process forks.
- extra = ""
- if _TEST_NAME_FILE: # pragma: debugging
- with open(_TEST_NAME_FILE) as f:
- test_name = f.read()
- extra = "." + test_name
- data_suffix = "%s%s.%s.%06d" % (
- socket.gethostname(), extra, os.getpid(),
- random.randint(0, 999999)
- )
-
self.get_data()
- self.data_files.write(self.data, suffix=data_suffix)
+ self.data_files.write(self.data, suffix=self.data_suffix)
def combine(self, data_dirs=None):
"""Combine together a number of similarly-named coverage data files.
@@ -1159,7 +1141,3 @@ def process_startup():
cov.start()
cov._warn_no_data = False
cov._warn_unimported_source = False
-
-
-# A hack for debugging testing in sub-processes.
-_TEST_NAME_FILE = "" # "/tmp/covtest.txt"
diff --git a/coverage/data.py b/coverage/data.py
index fb0fdb97..db575e17 100644
--- a/coverage/data.py
+++ b/coverage/data.py
@@ -2,8 +2,11 @@
import glob
import os
+import random
+import socket
from coverage.backward import iitems, pickle
+from coverage.debug import _TEST_NAME_FILE
from coverage.files import PathAliases
from coverage.misc import file_be_gone
@@ -263,6 +266,21 @@ class CoverageDataFiles(object):
"""
filename = self.filename
+ if suffix is True:
+ # If data_suffix was a simple true value, then make a suffix with
+ # plenty of distinguishing information. We do this here in
+ # `save()` at the last minute so that the pid will be correct even
+ # if the process forks.
+ extra = ""
+ if _TEST_NAME_FILE: # pragma: debugging
+ with open(_TEST_NAME_FILE) as f:
+ test_name = f.read()
+ extra = "." + test_name
+ suffix = "%s%s.%s.%06d" % (
+ socket.gethostname(), extra, os.getpid(),
+ random.randint(0, 999999)
+ )
+
if suffix:
filename += "." + suffix
data.write_file(filename)
diff --git a/coverage/debug.py b/coverage/debug.py
index fbffc569..b4c65d26 100644
--- a/coverage/debug.py
+++ b/coverage/debug.py
@@ -9,6 +9,9 @@ import os
# This is a list of forced debugging options.
FORCED_DEBUG = []
+# A hack for debugging testing in sub-processes.
+_TEST_NAME_FILE = "" # "/tmp/covtest.txt"
+
class DebugControl(object):
"""Control and output for debugging."""
diff --git a/tests/coveragetest.py b/tests/coveragetest.py
index 1623ef99..2f488616 100644
--- a/tests/coveragetest.py
+++ b/tests/coveragetest.py
@@ -12,7 +12,7 @@ import sys
import coverage
from coverage.backunittest import TestCase
from coverage.backward import StringIO, import_local_file, string_class
-from coverage.control import _TEST_NAME_FILE
+from coverage.debug import _TEST_NAME_FILE
from coverage.test_helpers import (
EnvironmentAwareMixin, StdStreamCapturingMixin, TempDirMixin,
)
diff --git a/tests/test_data.py b/tests/test_data.py
index a53330f1..1f0aecfd 100644
--- a/tests/test_data.py
+++ b/tests/test_data.py
@@ -174,9 +174,7 @@ class DataTest(DataTestHelpers, CoverageTest):
apy = canonical_filename('./a.py')
sub_bpy = canonical_filename('./sub/b.py')
- self.assert_summary(
- covdata3, { apy: 4, sub_bpy: 2, }, fullpath=True
- )
+ self.assert_summary(covdata3, { apy: 4, sub_bpy: 2 }, fullpath=True)
self.assert_measured_files(covdata3, [apy,sub_bpy])
diff --git a/tests/test_farm.py b/tests/test_farm.py
index d8d4c0fa..8b17251b 100644
--- a/tests/test_farm.py
+++ b/tests/test_farm.py
@@ -14,7 +14,7 @@ from nose.plugins.skip import SkipTest
from tests.helpers import run_command
from tests.backtest import execfile # pylint: disable=redefined-builtin
-from coverage.control import _TEST_NAME_FILE
+from coverage.debug import _TEST_NAME_FILE
def test_farm(clean_only=False):