Skip to content

Commit

Permalink
Fix coverage tests on MacOS
Browse files Browse the repository at this point in the history
Testing Done:
build-support/bin/ci.sh on my mac laptop.

ci green @ https://travis-ci.org/pantsbuild/pants/builds/35870205

Bugs closed: 595

Reviewed at https://rbcommons.com/s/twitter/r/1057/
  • Loading branch information
ericzundel committed Sep 21, 2014
1 parent b89e83a commit 0e3748e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/python/pants/backend/python/python_chroot.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ def __init__(self,
self._extra_requirements = list(extra_requirements) if extra_requirements else []
self._platforms = platforms
self._interpreter = interpreter or PythonInterpreter.get()
self._builder = builder or PEXBuilder(tempfile.mkdtemp(), interpreter=self._interpreter)
self._builder = builder or PEXBuilder(os.path.realpath(tempfile.mkdtemp()),
interpreter=self._interpreter)
self._conn_timeout = conn_timeout

# Note: unrelated to the general pants artifact cache.
Expand Down Expand Up @@ -92,7 +93,7 @@ def debug(self, msg, indent=0):
print('%s%s' % (' ' * indent, msg))

def path(self):
return self._builder.path()
return os.path.realpath(self._builder.path())

def _dump_library(self, library):
def copy_to_chroot(base, path, add_function):
Expand Down
13 changes: 12 additions & 1 deletion src/python/pants/backend/python/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ def _format_string_list(values):
return '\n\t{values}'.format(values='\n\t'.join(values))

def _generate_coverage_config(self, source_mappings):
# For the benefit of macos testing, add the 'real' path the the directory as an equivalent.
def add_realpath(path):
realpath = os.path.realpath(path)
if realpath != canonical and realpath not in alternates:
realpaths.add(realpath)

cp = configparser.SafeConfigParser()
cp.readfp(Compatibility.StringIO(self.DEFAULT_COVERAGE_CONFIG))

Expand All @@ -138,7 +144,11 @@ def _generate_coverage_config(self, source_mappings):
cp.add_section('paths')
for canonical, alternates in source_mappings.items():
key = canonical.replace(os.sep, '.')
cp.set('paths', key, self._format_string_list([canonical] + list(alternates)))
realpaths = set()
add_realpath(canonical)
for path in alternates:
add_realpath(path)
cp.set('paths', key, self._format_string_list([canonical] + list(alternates) + list(realpaths)))

# See the debug options here: http://nedbatchelder.com/code/coverage/cmd.html#cmd-run-debug
if self._debug:
Expand Down Expand Up @@ -174,6 +184,7 @@ def compute_coverage_modules(target):
# Take the approach of registering a plugin that replaces the pycov plugin's
# `pytest_terminal_summary` callback with a noop.
with temporary_dir() as plugin_root:
plugin_root = os.path.realpath(plugin_root)
with safe_open(os.path.join(plugin_root, 'pants_reporter.py'), 'w') as fp:
fp.write(dedent('''
def pytest_configure(__multicall__, config):
Expand Down

0 comments on commit 0e3748e

Please sign in to comment.